Merry Christmas!

The Source:

010011010110010101110010011100100111100100
100000010000110110100001110010011010010111
001101110100011011010110000101110011001000
000111010001101111001000000110000101101100
011011000010000001101111011001100010000001
111001011011110111010100100001000011010000
101000001101000010100100010101101110011010
100110111101111001001000000111100101101111
011101010111001000100000011010000110111101
101100011010010110010001100001011110010111
001100100000011000010110111001100100001000
000111001101110000011001010110111001100100
001000000110000100100000011001110111001001
100101011000010111010000100000011101000110
100101101101011001010010000001110111011010
010111010001101000001000000111100101101111
011101010111001000100000011001100110000101
101101011010010110110001111001001000000110
000101101110011001000010000001111001011011
110111010101110010001000000110110001101111
011101100110010101100100001000000110111101
101110011001010111001100100001

Check for AJAX Request in PHP

A simple PHP function to check if the request comes from an AJAX XMLHttpRequest.
Use it if you want your page or script to behave differently when called from AJAX.

The Function:

function isAjax(){
    return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}

Detecting Mobile Devices Accessing Your WordPress Site

Mobile web surfing is continuing to evolve on a larger scale. This is why detecting those users who are visiting your WordPress blog through a mobile device and redirecting them to a mobile version of your site is important. In order to achieve this, you first have to get the code from detectmobilebrowsers.mobi and upload it to your theme directory.

Then, all you simply have to do is open your header.php file and place the following at the top of the file. Remember to edit line 4 to where you’d like to redirect mobile users.

The Source:

include('mobile_device_detect.php');
$mobile = mobile_device_detect();
if ($mobile){
    header('Location: http://your-website.com/?theme=Your_Mobile_Theme');
}

Human readable and by size sorted disk usage (du) in BASH

This is a quick tip to fix a problem that has always bugged me.
When showing disk usage in a human readable form (KB, MB, GB) for each subdirectory using du -sh *, how can you properly sort it by size.

If you just want the solution here it is as “one-liner”:

function duf {
    du -sk "$@" | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done
}

Just put this function into your ~/.bashrc to make it permanent.

The expanded code:

function duf {

    // get usage in KBytes and sort
    du -sk "$@" | sort -n | while read size fname;
   
    // loops for each size
    do for unit in k M G T P E Z Y;
   
        // if size<1024 we found the correct suffix
        if [ $size -lt 1024 ];
       
        // display the size
        then echo -e "${size}${unit}\t${fname}";
       
    // line completed
    break;
    fi;
   
    // for each sizes suffix divide by 1024
    size=$((size/1024));
   
    done;
    done
}

When done, you can use your new function like this: duf /*.