Human-friendly sorted du output

Using the following one-liner, get a human-friendly overview of the size of the files and directories in the current directory, sorted by size.

du -d1 . | sort -n | xargs -I myline python -c "from math import log;ss='myline'.split();n=int(ss[0]);k=1024.;d=int(log(n)/log(k));print '{:10.2f} {}B\t{}'.format(n/k**d, ['K','M','G','T','P'][d], ' '.join(ss[1:]))"


Sweet Japanese omelet (卵焼き) made in a 10.5 x 20.5 cm square frypan.
(1 person)

1 egg
1 tbsp. sugar
0.5 ml honkatsu dashi (本かつおだし)

Whip the egg and sugar, add dashi, mix. Add a thin layer of the mixture to the frypan, roll into a square, repeat.

iRiver Story HD PDF Preparation

A few steps you can do in order to make pdf files more readable on your iRiver Story HD ebook reader.

1. Remove margins. White margins take up unnecessary space which restricts the maximum possible font size.
Use pdfcrop to do this in Ubuntu. sudo apt-get install texlive-extra-utils

2. More to come…

Linux Dual Monitor Xorg Setup That Works With OpenGL

In order to make OpenGL create windows that are actually the indented size and not the (very) wide width of the dual monitor screen, add this line to your Screen section in xorg.conf:

Option "Metamodes" "DFP-0: 1920x1080 +1920+0, DFP-2: 1920x1080 +0+0; 1280x1024,1280x1024; 1024x768,1024x768; 800x600,800x600; 640x480,640x480; 1920x1080,NULL;  1280x1024,NULL; 1024x768,NULL; 800x600,NULL; 640x480,NULL;"

Edit it accordingly to include the modes you want. Note that it is the WIDTHxHEIGHT,NULL modes that enables OpenGL to create the windows with the correct desired size.

Automatically replace uploaded image with smaller one in WordPress

Found this here
And the other tip here

This is a lifesaver (or at least, disk space saver) when you have users who upload pictures directly from their digital cameras which are several megs in size.

Paste this into your functions.php file.

function replace_uploaded_image($image_data) {
    // if there is no large image : return
    if (!isset($image_data['sizes']['large'])) return $image_data;

    // paths to the uploaded image and the large image
    $upload_dir = wp_upload_dir();
    $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
    $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file'];

    // delete the uploaded image

    // rename the large image

    // update image metadata and return them
    $image_data['width'] = $image_data['sizes']['large']['width'];
    $image_data['height'] = $image_data['sizes']['large']['height'];

    return $image_data;

This might cause WordPress to yell something about add_filter not being defined. This is caused by plugin.php being loaded after functions.php, simply change this by changing

require( ABSPATH . WPINC . '/functions.php' );
require( ABSPATH . WPINC . '/plugin.php' );


require( ABSPATH . WPINC . '/plugin.php' );
require( ABSPATH . WPINC . '/functions.php' );

in wp-settings.php.

How to make Wine open links in your browser

This is how:

1. HKEY_CURRENT_USER (a.k.a HKCU) -> Software -> Wine and look for a key called “WineBrowser”, if it does not exist, create it. Under the newly created “WineBrowser” key, create a string called “Browsers” with the following value:


2. HKEY_CLASSES_ROOT -> http -> shell -> open -> command and edit the data value by adding “%1″ at the end of the line, so that it looks like this:

C:\windows\system32\winebrowser.exe -nohome "%1"

Enable aac, h264 and other restricted encodings in ffmpeg

These two threads describe excellent techniques for doing just that:
Advanced Version
Easy version

This one also helps:
Fixing ffmpeg on Ubuntu

The reason I had to do this in the first place was because I wanted to amplify the volume on the h264 encoded mp4 videos my digital camera recorded with the audio in aac format.

To increase the audio volume, simply do this:

ffmpeg -i infile.mp4 -vcodec libx264 -vol 2400 outfile.mp4

Where 2400 stands for increasing the audio volume by 2400% (yes, my microphone kind of sucks :/ )

Enable VPN routing via Firestarter

I had some trouble getting my VPN to work with Firestarter, so I’ll post this simple solution I found after some googling.

In Firestarter:
Go to Preferences->Network Settings.
Choose Ethernet Device (eth0) (yours may be different) as Internet connected network device.
Choose Routed IP Tunnel (tun0) (yours may be different) as Local network connected device.
Place a check mark in Enable Internet Connection Sharing box.
Stop and restart Firestarter.

Originally found here.

JR syntax highlighting in gedit

There were no syntax highlighting for the programming language JR in gedit, so I wrote one myself.

This will work for Ubuntu 9.10, but it may work for others as well.

How to install:
1. Download jr.lang.
2. Place it in either




3. Download jr.xml.
4. Place it in (create it if it doesn’t exist yet)


5. Update the mine database:

cd ~/.local/share
update-mime-database mime

All done! You should now get JR syntax highlighting when opening .jr files in gedit.

Note: The directory paths are based on an Ubuntu system and might be different for other distributions.

Alternatively, you can just run this script to install it automatically:

wget -O jr.lang
wget -O jr.xml
mkdir -p ~/.local/share/gtksourceview-2.0/language-specs
mv jr.lang ~/.local/share/gtksourceview-2.0/language-specs/
mkdir -p ~/.local/share/mime/packages
mv jr.xml ~/.local/share/mime/packages/
update-mime-database ~/.local/share/mime

How to find out and change file encoding in Ubuntu

First, you can find a file’s encoding like this:

$ file oldfilename.txt 
oldfilename.txt: ISO-8859 English text

Then, if you want to convert the file oldfilename.txt from ISO-8859 to UTF-8 and call the new UTF-8 file newfilename.txt you do like this:

$ iconv -f ISO-8859-1 -t UTF-8 -o newfilename.txt oldfilename.txt

Note that the file command says ISO-8859 and that you have to use ISO-8859-1 in the iconv command.
For a long list of available iconv encodings, use

$ iconv -l

How to Connect to Chalmers VPN in Ubuntu Karmic (9.10)

This example is for Chalmers PPTP VPN.

1. Install network-manager-pptp.

sudo apt-get install network-manager-pptp

2. Add a new VPN connection in Network Connections. Choose PPTP, create.
3. Add the following and only the following

User name: NET\your-username-here
Password: your-password-here

Click Advanced...
In Authentication, select only

In Security and Compression select all and
Security: All Available (Default).

4. Restart your computer. This is important, don’t miss out on this one.
5. When back in Ubuntu, connect to Chalmers VPN, then click Deny when it asks
about the keyring. Enter your password for your account and then select Always Allow
when it asks about the keyring the next time.
6. Done!

Why all this restarting, denying, re-entering passwords and stuff you ask? It seems like there’s a bug in network-manager-pptp which will hinder you from connecting if you don’t follow the above procedure. Don’t ask me why this bug isn’t fixed, but I don’t think doing the above steps are that gruesome in order to get the simple functionality of an otherwise well-working VPN GUI for Ubuntu.

Salmon skewer with bulgur

A delicious and yet simple dish.

Preparation time:
10 minutes
500g salmon
2 tbsp. cooking oil
1 tsp. salt
1 tsp. lemon-pepper
1 tbsp. sesame seeds
4 dl bulgur
8 dl chicken stock
1 tbsp. neutral cooking oil
2 tbsp. chopped leek
1/2 zucchini
1/2 bell pepper
salt and grounded black pepper
Pesto sauce:
2 dl crème fraiche
2 tbsp. pesto

Pesto sauce:
Mix crème fraice and pesto. Let it cool down until serving.

Trim and chop the leek finely. Cut the zucchini and bell pepper into cubes. Sizzle the leek and bulgur in oil in a deep, wide kettle. Pour 4 dl of stock and cook on low heat during constant stir. Add more stock as time goes by. When the groats are soft they are done. Finish off by adding zuccini and bell pepper along with salt and newly grounded black pepper.

Salmon Skewer:
Cut the fish into smaller bits and skewer them. Brush some oil on and season with salt and lemon-pepper. Add sesame seeds over it all. Grill the skewers until they get a nice color.

Installing Git on a shared webhost

This great article describes how to install git on a remote machine where you don’t have root access. It’s really useful if you want to use your web host’s server as a place to backup your code. You’ll need SSH access to the server though.

Just to make sure this information stays online, I’ve just made a copy of the article’s most useful part below:

This rpm needs to be installed, but you won’t be able to use the regular rpm installer because this requires root access. You can extract the rpm file with the command:

rpm2cpio git-1.6.x.x.rpm | cpio -imdv

This will create a usr/ directory in currect directory. You best move this directory to your home root:

mv usr ~/usr

Now we are almost there, we only need to add the directory to $PATH variable. Doing this will make it possible to execute the command git from anywhere. Open your ~/.bashrc file with your favorite editor (vim or pico) and add the following line:

export PATH=$PATH:$HOME/usr/bin:$HOME/usr/libexec/git-core

And that’s it. To activate this change, run source ~/.bashrc or log out and in again.

Get remote HTML with PHP

This piece of code retrieves the HTML code from a page, which you can then process and manipulate as you see fit. In the below example, the source code of my page is retrieved.

// This variable will hold the code
$content = "";

// You have to divide host and the rest of the url,
// so in this example, the full url you wanted to get
// would be
// As you can see, you don't have to specify the
// protocol used.
$host = "";
$url = "/user/CaseuS_";

// Open the connection on port 80
// $errno and $errstr can be used to
// get the error number and error message
// in case something went wrong.
// 30 stands for the timeout, in seconds,
// that we use for the connection attempt.
$fp = fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp)
    echo "$errstr ($errno)<br />\n";
    $out = "GET $url HTTP/1.1\r\n";
    $out .= "Host: $host\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp))
        $content .= fgets($fp, 128);

// Do something with $content, e.g. output the whole code:
echo $content;

Google CSE Module URL Rewrite

I found a great tip regarding fully integrating the Google CSE module with the rest of your Drupal installation.

Basically, the tip I found to be really useful was the rewrite rules for the Google CSE search itself. Since Drupal comes with this built-in search module which is easily accessible at, it’s really great to use Apache URL rewrite and redirect users from that Drupal search (which I think isn’t really that good) to the Google CSE result page. The only real change from the original page is the last line of the code, which sort of sums things up and enables the user to search directly from “search/your-terms-here”. Take a look at the code below!

In your .htaccess file, add the following lines:

RewriteRule ^search$ /search/google [R=301,NC,L]
RewriteRule ^search/node$ /search/google [R=301,NC,L]
RewriteRule ^search/node/(.*)$ /search/google?query=$1 [R=301,NC,L]
RewriteRule ^search/taxonomy_search$ /search/google [R=301,NC,L]
RewriteRule ^search/taxonomy_search/(.*)$ /search/google?query=$1 [R=301,NC,L]
RewriteRule ^search/((?!google).*)$ /search/google?query=$1 [R=301,NC,L]

Idea from…

Fix endless redirection issue with Drupal Google CSE and Search 404 module

When using the Search 404 module and Google CSE (Custom Search Engine) together, the result is an endless redirection that will… well, you know, loop endlessly and stop you from doing more important things, like getting to your search results.

The problem occurs in at least Search 404 version 6.x-1.7.

This can be easily fixed by changing one line into two in the /sites/all/modules/search404/search404.module file.

On line 117, in function search404_page(), change

drupal_goto ('search/google/'. $keys);


$_REQUEST['destination'] = 'search/google/'. $keys;

Fix Spotify sound in Ubuntu Karmic (9.10)

When I first ran Spotify through Wine after just having had installed the new Ubuntu Karmic I immediately noticed that the sound from Spotify wasn’t the best, really. Actually, I’m being a bit too kind here. The sound was horrible! It sounded like the audio wasn’t decrypted or something like that since all I heard was a lot of noise.

Luckily, there is a solution to this.

  1. Make sure the package “wine1.2″ is installed:
    sudo apt-get install wine1.2
  2. Type winecfg in terminal, go into the Audio
    tab and change the following as below:
    Sound Drivers: Check both OSS and ALSA
    Hardware Acceleration: Full
    Default Sample Rate: 44100
    Default Bits Per Sample: 16

Just another random page.