Category Archives: Tumble

Google Webmaster Tools has a very interesting widget to improve the usefulness of your 404 pages with little or no effort. It brings something like “Did you mean?” for your URLs, suggests links like pages in a higher hierarchy, and adds a Google Search form.

Google 404 Webmaster Tool

First, include this snippet where you want the suggestions to appear. For WordPress blogs, this is typically the 404.php file in your themes folder ((The full path would be /wp-content/themes/yourtheme/404.php. Create it if it doesn’t exist)).



Optionally, edit its look and feel by extending this base stylesheet. Tip: you can hide, for example, the search box, by adding display: none to #goog-wm li.search-goog


    /* Widget content container */
   #goog-wm { }

    /* Heading for "Closest match" */
   #goog-wm h3.closest-match { }

    /* "Closest match" link */
   #goog-wm h3.closest-match a { }

    /* Heading for "Other things" */
   #goog-wm h3.other-things { }

    /* "Other things" list item */
   #goog-wm ul li { }

    /* Site search box */
   #goog-wm li.search-goog { }

    /* Search text input */
   #goog-wm-qt {}

    /* Search button */
   #goog-wm-sb { }

Then you’re done! Check mine out (deliberately wrong url) for an example.

The default shell for Leopard users is Bash. Although many GNU/Linux users are familiar with it, not all Mac users take full advantage of its power. Here are some very useful commands and tips I use routinely.

Users and login

Use the root superuser

sudo su -

Alter login variables (such as $PATH, $EDITOR)

nano ~/.profile

Other available shells

  • /bin/ksh
  • /bin/tcsh
  • /bin/csh
  • /bin/zsh

Files management

Output the contents of a file

cat /some/thing

Get 20 lines from the end of a file

tail -n 20 /some/thing

Get the first 20 lines of a file

head -n 20 /some/thing

Create an empty file

touch /some/thing

Redirect the output of a command to a file (overwrites)

command > /some/thing

Redirect the output of a command to a file (appends)

command >> /some/thing

Append the timestamp to a file

touch /backups/backup_`date +%s`.txt

Change to the last directory you were in

cd /var
cd /etc
cd - # will take you to /var

List file size in human-readable units

ls -lh /dir/or/file

Available editors

  • /usr/bin/vi
  • /usr/bin/vim
  • /usr/bin/nano

Applications and processes

Run a process in the background

command &

List running processes

ps ax

The first column will be the PID

Kill a process by pid

kill -9

Kill a process or processes by name (e.g: the Dock)

killall Dock

Open an application (Mac-only)

open /Applications/iTunes.app/

First of all, we make our file start like this.

#!/usr/bin/env php

This allows us to run the script without prefixing it with the “php” command, and instead we can run it like this:

chmod +x myscript  # This gives execution permissions to the script, do it only once
./myscript --first=option --second --third=option

If we want our script to take options like in the example above, we can use this snippet:

$options = array();

foreach ($argv as $arg){
	preg_match('/\-\-(\w*)\=?(.+)?/', $arg, $value);
	if ($value && isset($value[1]) && $value[1])
		$options[$value[1]] = isset($value[2]) ? $value[2] : null;
}

The $options array will hold the supplied options. You can then use them like this:

if (!isset($options['somevalue']))
	// show an error

if (isset($options['dosomething']))
	// do something

Open up terminal. Copy the link of the latest Lua version and download it:

cd /tmp
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz

Extract and compile:

tar -xzvf lua-5.1.4.tar.gz
cd lua-5.1.4
make macosx

Test and install (if test goes through)

make test
sudo make install

And you’re done!