PHP: Naturally sorting arrays

Posted by & filed under PHP, Programming.

I recently had an issue where I was sorting a array using php’s sort() function. This worked fine, except the ordering gets out of logical order when you get into the double digits. Example:


This is where natsort() comes in. This is PHP’s natural sorting algorithm. It sorts based on how a human would sort a list rather than the way a machine would.

So I replaced



 $narray = array_values($narray);

Problem solved!

Linux: Find base64_decode in files

Posted by & filed under Linux.

Bad hax0rs! base64_decode is used by hackers frequently when they hijack a site to obfuscate their malicious code. This quick BASH one-liner will find files containing this evil function and lists them out:

find . -name '*.php' | while read  FILE; do  if grep  'eval(base64_decode' "$FILE"; then echo  "$FILE" >>  infectedfiles; else echo "$FILE"  >> notinfected; fi ; done

Linux: Find files modified between dates

Posted by & filed under BASH, Linux.

I found a handy technique to find files modified between a specific date. In essence, we touch two temp files, setting the modified dates to the range we want to find:

touch temp -t 201104141130
touch ntemp -t 201104261630

Note the date is yyymmddtime.

Then we run the find command:

find /path/to/folder/ -cnewer temp -and ! -cnewer ntemp


Converting a white background to transparent

Posted by & filed under Web Development.

Here is a great method to remove the background of a image without dealing with the ugly edged the magic wand tool can produce.

1. copy the image to a new layer and delete the background layer
2. copy the image to a new layer again and INVERT it
3. copy the inverted layer into the clipboard, and switch off its visibility for now
4. go back the the first image and create a layer mask
5. press ALT whilst clicking on the mask thumbnail
6. paste the inverted image, then click back to the image thumbnail in the layer palette
7. duplicate this new layer until necessary (5 times?) and delete the inverted layer you created at the start
8. merge down the layers one by one (Ctrl-E) choosing to “apply mask” each time

Google AJAX APIs & Yii

Posted by & filed under Uncategorized.

I was snooping around the Yii documentation and came across system.web.helpers CGoogleApi. It’s here:…
Anyway, my interest was piqued, so I took a look at whatGoogle has to offer. I was expecting calendar, maps, search yadda. There LOTS more!

Google has a playground that you can use to demo the APIs:

Translation, RSS Feeds, Maps/Directions, and all the other Google services are all right there!

jQuery-UI Themeroller & Yii Widgets

Posted by & filed under Uncategorized.

Here is the lowdown on theming jQuery:

  • Create the Theme:
  • Extract and upload the contents of the theme’s css directory to /css/jui (we set this later on…)
  • Add themeUrl, theme, and cssFile (see example below). Be sure to set them according to the path of the files you just uploaded.
    themeurl is the base folder for the theme… usually in the css folder. I use /css/jui.
    theme is the folder name inside e.g. /css/jui/humanity
    cssfile is the theme’s cssfile.

$this->widget('zii.widgets.jui.CJuiAccordion', array(

/* optional: change visual
* themeUrl: "where the themes for this widget are located?"
* theme: theme name. Note that there must be a folder under themeUrl with the theme name
* cssFile: specifies the css file name under the theme folder. You may specify a
* single filename or an array of filenames
* try
'themeUrl' => Yii::app()->baseUrl.'/css/jui' ,
'theme'=>'humanity', //try 'bee' also to see the changes
'cssFile'=>array('jquery-ui.css' /*,anotherfile.css, etc.css*/),