Friday, February 20, 2009

What content would you like to see next?

Hey guys. I was just wondering - what content would you like to see posted next? Is there any particular subject of interest or question on anyone's mind?

Feel free to answer in the comments...

Tuesday, February 17, 2009

Don't wanna be Obama's Elf

How to update a single field in CakePHP

Here's a quick line of code to demonstrate how to update a single field in CakePHP.

Suppose we will be updating a field named 'confirmed' in a model called 'User' with the id of 5. We will then have an array with just that value, like this:


$data = array(
'User' => array(
'id' => 5,
'confirmed' => 1
)
);


We should then pass it on to a save function:

$this->User->save( $data, false, array('confirmed') );


You can RTFM about the save() function here.

Wednesday, February 11, 2009

How to undelete text files on linux

Today was a hard day. Someone accidentally deleted a bunch of files with code containing the last two days' work.

Fortunately, all the files were successfully recovered. I'll share the way that worked here with you.

First of all, the moment you lose your text data, make sure that if you can, you unmount the drive the files were on, so you won't overwrite the lost data.

Then you will have to run a utility called strings. Basically what it does is extracting all string data from it's input, and outputs it to STDOUT or whatever output you specify.

We will tell it to read our partition on the hard drive the lost files were. (Learn more about Linux partitions) and output it to a file on another partition.

So the command should look something like this:
strings /dev/sda1 > /some/path/for/output.txt


Note that '/dev/sda1' should be replaced by your partition path, and you should provide a path to where you want the output file to be. (NOTE: AVOID WRITING IT TO THE SAME PARTITION AT ANY COST. THE RESULTING FILE WILL BE HUGE, MORE THAN 10GB, AND YOU DON'T WANT TO OVERWRITE YOUR PRECIOUS DATA!).

After the process finishes (takes quite a while), you should have a HUGE text file that contains ALL of the text from your hard drive, deleted or not.

Now, basically all you need to do is to grep and locate the text you lost inside the whole mass.

Hope it helps you! It sure helped me!

Tuesday, February 10, 2009

Linux - working with filenames and directories starting with a - (dash)

I use SVN daily on my Linux development server, but today I ran into a silly problem that took me some figuring out.

If you try to work with filenames that start with - (dash) such as "-filename.ext", you will get errors such as:
svn: invalid option character: i
Type 'svn help' for usage.


After some looking around, the solution for it was, instead of:
svn rm -filename.ext

To pass '--' as the first argument:
svn rm -- -filename.ext


Hope it helps anyone out there.