Archive for May, 2010

The last week in Hong Kong

The last week in Hong Kong has started. It feels sad to leave this place just as the summer finally hits Hong Kong after a very moist and cloudy spring. It’s been a terrific year abroad and I don’t really see how I will adapt to the Swedish life again. The food, climate, beautiful surroundings, and one of the biggest, most alive, mega-cities on this planet. Returning to small Gothenburg will be interesting to put it gently.

The campus and environment surrounding the school is one of a kind and to have such a place next to Hong Kong is incredible.

Putting Chrome’s cache in the ram

The Chrome web browser is changing the way we browse with it’s speed and focus on content. But, it’s killing my laptop’s battery and hard drive with its constant reading and writing to disk.

Luckily, Linux has a folder mounted in the ram, which means that reads and writes to this folder don’t affect the harddisk (it’s also about two orders of magnitude faster than my notebook disk). The downside is that the data disappears when the power goes out. That folder is most often called /dev/shm/ and I wanted to put Chrome’s cache in this folder, to avoid the constant writing to disk. But I wasn’t prepared to lose all my preferences, extensions, and saved data when the computer was powered down. So I wrote this script that copies the folder from /dev/shm/ mounted in the ram to the disk and this script runs whenever I exit Chrome.

This is how I put Chrome’s cache in the ram

mkdir /dev/shm/.personal_synced # The folder in ram

mkdir ~/.personal_synced # The mirrored folder on disk

I wrote this simple script that fires once every hour (I’m pretty sure it can be written in a simpler way, but I’m certainly a bash-newbie):

#!/bin/bash
# Sync the ramdisk to harddrive

foldername=”.personal_synced”
ramdisk=”/dev/shm/”$foldername
harddisk_copy=”/home/anders/”
backup=”/home/anders/”$foldername”.old”

# Remove the old backup
echo “removing $backup”
rm -fr “$backup”
# Make a copy of the old one
echo “Copies the latest backup $harddisk_copy$foldername”
mv -f “$harddisk_copy$foldername” “$backup”
# Copy from ram
echo “Copies $ramdisk to harddrive, $harddisk_copy”
cp -R “$ramdisk” “$harddisk_copy”

I want to make this sync-script fire when I exit Chrome. At first I tried to make it fire on shutdown but that proved harder than I thought. The following script synchronizes the ram-disk when Chrome exits, and I just replace the symbolic link in /usr/bin/google-chrome with this script.

#!/bin/bash
# Start Chrome with cache in the ram

/opt/google/chrome/google-chrome -user-data-dir=”/dev/shm/.personal_synced/google-chrome” “$@” && /home/anders/Scripts/syncRamdisk

All that is missing is a script that copies the disk-folder to ram when we boot our computer.

# The synced folder
cp -R /home/anders/.personal_synced /dev/shm/
chown -R anders /dev/shm/.personal_synced

# The chrome cache. I don’t want to sync this so it’s placed outside .personal_synced
mkdir /dev/shm/google-chrome
chown anders /dev/shm/google-chrome

I simply added the script to my Startup Applications, under System->Preferences.

Moving Chrome’s cache to our automatically synced folder

By moving the .config/google-chrome-folder to the synced folder, and replacing it with a symlinks, the work will be complete (I also move the cache to the ramdisk, but not to the synced folder. I see no point in spending time and space on keeping the cache):

mv ~/.cache/google-chrome /dev/shm/google-chrome
ln -s /dev/shm/google-chrome ~/.cache/google-chrome

mv ~/.config/google-chrome /dev/shm/.personal_synced/
ln -s /dev/shm/.personal_synced/google-chrome ~/.config/google-chrome

Notes:

/dev/shm/ is readable by anyone, it’s not very secure to put stuff in that folder.

Update: I adjusted the scripts, I had problems with root owning the folders which caused some problems.

Matlab and Ubuntu 10.04

Matlab 2009bWhen I started Matlab 2009b on my new install of Ubuntu Lucid Lynx (10.04) I had the problem that some keys weren’t working. Most notably, the [] didn’t work which is quite bad when writing Matlab-code. Also, the terminal outputs this message:

Warning: X does not support locale en_HK.utf8

The problem is that the locale is set to utf8 (small caps) while Matlab requires UTF-8. By specifying the locale before we start Matlab we solve the problem.

Remove the symbolic link to matlab in /usr/local/bin/matlab with

sudo rm /usr/local/bin/matlab

and create a script in its place:

sudo gedit /usr/local/bin/matlab:

and paste this as it’s content:

#!/bin/bash
# Start Matlab with the right encoding
echo “Starting Matlab with en_HK.UTF-8 coding”
LC_CTYPE=”en_HK.UTF-8″ /usr/local/Matlab2009b/bin/matlab

where you change en_HK to something that seems appropriate and is part of the list produced by locale -a. My Matlab is installed in /usr/local/Matlab2009b/.