poniedziałek, 12 grudnia 2011

środa, 7 grudnia 2011

[Learning Yii] Find by ID - One to rule them all

Yii is fun. If you understand it. I try to understand it everyday, so I will write about it from time to time.

How to get only 1 result from any table in your project using ID?

NameOfTable::model()->search criteria->columne name
ex:
TestPack::model()->findByPk(1)->name //means: in table TestPack find row with id 1 and show it's name
Fun starts, when you need to do more complex requests - then you can chain requests:
TestPack::model()->findByPk(Test::model()->findByPk($_GET['id'])->test_pack_id)->name

piątek, 2 grudnia 2011

How to change MAC address under Linux Debian Squeeze

Changing MAC address should be easy, and it almost is. There are plenty of methods. I like this one - it will work for simple LAN configuration with DHCP, for one session. There is also simple modification to make it permanent. If it will work for WLAN - I have no idea.

In Debian there is something called Networking Manager. Networking Manager, automagically manages your network. So if you want to change MAC addres for card, you must first disable Networking Manager for this card . To do so:

  1. Open /etc/network/interfaces<
  2. Uncomment
    iface eth0 inet dhcp
  3. Add line
    auto eth0
  4. Save

Be sure that Networking Manager doesn't remember about your card and reboot or do:

$ /etc/init.d/network-manager stop
$ /etc/init.d/network-manager start

Now you are ready to change MAC address:

$ ifdown eth0
$ ifconfig eth0 hw ether 01:02:03:04:05:06
$ ifup eth0

If you want to revert to your original MAC address you have to repeat commands, giving your real MAC or reboot computer. I didn't find any method for restoring MAC to original state, without wiritng it again. If you know one, let me know.

Make it permanent

If you want to change MAC for longer than just one session in /etc/network/interfaces add another line, to stated above, under last line:

hwaddress ether 01:02:03:04:05:06

Macchanger

There is also program called macchanger, which does the same, but in one line. It's OK, but it still doesn't have option to restore real MAC address.

wtorek, 22 listopada 2011

HTML5 local storage in browser vs cookie

Local storage is cool - it behaves as cookie but allows you to keep more than cookie (cookie size limit is 4KB, and local storage allows you 5MB), and it is much more simple in use (there is no need to set expire date): To write to local storage:
localStorage.setItem("name_of_item", your_data)
To read from local storage:
your_data = localStorage.getItem("name_of_item")
If you want to keep some data only for current session, use:
sessionStorage
instead of
localStorage
Btw. everything you put into storage, will become string. If it doesn't want to fit - make it string.

Good tutorial about PHP objects, classes etc.

If you already know functions in PHP and want to make another step into world of classes, objects, etc.: http://www.killerphp.com/tutorials/object-oriented-php/php-objects-page-1.php

poniedziałek, 31 października 2011

How to convert to 8-bit 256 palleted png using php imagick

If you want to convert and save any image using pure php imagick, to palleted, 8-bit png:

$thumb->setImageType (4); //sets to 256 colors
$thumb->setImageFormat('png');
$thumb->setImageDepth('8'); // :)
$thumb->setImageCompressionQuality(90); //u can try also 95
$thumb->writeImage('temp.png');