Twitter Updates

Tuesday, 31 March 2009

Apple Student Discount

For the best students discounts on Apple products visit from in side you educational institutions network. If they are registered you will see the lowered prices.

Saturday, 28 March 2009

Ruby list directory contents

Ruby listing directory contents:
Dir.entries returns the array,
Dir.foreach itterates.
#!/usr/bin/env ruby 

mycontents = Dir.entries("/")
mycontents.each { |x|
puts x

Dir.foreach("/") { |x|
puts x

Friday, 27 March 2009

Sony BDP-S350 Resetting Screen Resolution

I bought a Sony BDP-S350 Blu-Ray player a while a go, but recently had to return my Samsung A686 Screen and used an older lower resolution monitor. When first switching back to the older screen I got the error message this screen does not support this resolution aargh!

Any way I found the manual online

And you wait 30 seconds with out doing anything, this means that all the menus will have defaulted back to a known state. Then press and hold stop on the player (not the remote) for 10 seconds, then the player defaults back to the lowest resolution and your ready to go again.

Thursday, 26 March 2009

Ubuntu adding/archiving on to new hard drive

So you just got a new bigger hard drive and want to use it to replace the main storage device on your Ubuntu Linux server, or just add the extra storage to it.

First powerdown (may not be necesariy with SATA) connect new drive and power up.
loggin and get to the terminal.

Find out the new device name, likely to be some thing along the lines of /dev/sdb
$ sudo fdisk -l
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Device Boot Start End Blocks Id System
/dev/sda1 1 121601 976760032 83 Linux

Disk /dev/sdb: 1500.3 GB, 1500301910016 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe53eaeaf

Device Boot Start End Blocks Id System

Not Formatted

It is the unformatted drive that we had to look out for.
Next Creat a partition table, It is a storage device so only want the one partition.

$ sudo fdisk /dev/sdb
press n to create new partition choose primary, the defaults should be good for use the full disk.
press w to save changes to disk.

This has created partition /dev/sdb1, which requires formatting for ext3 do:
$ sudo mke2fs -j /dev/sdb1

Creat a point to mount it, I only want this to be temprorayt but if it is for permenent installation choose the names carfully.
$ sudo mkdir -p /mnt/insertHostName/tempdrive

Mount it (One off)
$ sudo mount -t ext3 /dev/sdb1 /mnt/insertHostName/tempdrive/

To mount the drive on sytem restarts do:
$ sudo vim /etc/fstab
added this line
/dev/sda1 /mnt/hostname/partitionname ext3 rw,auto,async,errors=remount-ro 0 1
then reload the fstab (mount the new drive)
$ sudo mount -a

Now start the Archiving process (Copying the files from old drive on to new).
The -a flag is very good for this it will Recursively copy maintaining permissions, Access dates and recreate links.
$ sudo cp -a /mnt/insertHostName/oldDrive/* /mnt/insertHostName/tempdrive/

once the copy is complete you can compare the space used available using:
$ df -h
>Filesystem Size Used Avail Use% Mounted on
>/dev/sda1 925G 866G 12G 99% /mnt/insertHostName/oldDrive
>/dev/sdb1 1.4T 866G 451G 66% /mnt/insertHostName/tempdrive

Wednesday, 25 March 2009

Get those pesky .DS_stores off my network

Mac OS X has a very annoying habit of creating a .DS_store file in every folder it visits.

This is very annoying in a mixed OS network. So to disable this behaviour for remote drives (Samba, ftp, webdav) you can just enter this at the command line:
$ defaults write DSDontWriteNetworkStores true

To get at the command line (Terminal) you find it in /Applications/Utilities/

Beware though that it is the .DS_store that finder uses to decide on file location when in grid view and stores the notes on files in there as well. So these features (Notes and rearranging the icons) will be reset every time you leave the folder.

Sources 1 2

Why put a laptop drive in a desktop pc?

This is a follow on from my Low Power Server recommendation

Why do I keep talking about laptop drives:
A laptop drive in a fully active Read/Write state uses only 3 watts and can idle at less than 1Watt and when it spins down is next to nothing at all, and has ten times the life span of a desktop drive in terms of spin up/down toggles, but they are a lot more expensive per GB than a standard 3.5" desktop drive.

So extending the life of your server drives, getting better value for money and saving power can be reached by combining the 2 types of drive.

The bulk of your storage should sit on a 3.5" desktop drive, cheap storage. The server should spin down this power hungry drive after it has not been used for some thing like 1 hour, this ensure it is not spinning up/down all day, but saves loads of power when inactive for periods of time (You go to work and sleep at night, don't you?).

The Operating System should live on a 2.5" laptop drive which will be on for most of the time (because of writing to log files) but could handle a really short spin down inactivity time if you wished. This greatly reduced the idle power of your PC, assuming that you used a low power mother board and cpu.

Power Dissipation of laptop drive from Western Digital
Read/Write 2.50 Watts
Idle 0.85 Watts
Standby 0.25 Watts
Sleep 0.10 Watts

Power Dissipation of desktop drive from Western Digital
Read/Write 6.00 Watts
Idle 3.7 Watts
Standby 0.80 Watts
Sleep 0.80 Watts

Tuesday, 24 March 2009

Low Power Server Recommendations

Every one needs a low power server, my current recommendations are:

Option [1]
If you only require a Network drive this is a really good (cheap/simple) option (it does include some basic server functionality)
Icy Box Dual Disk with Gigabit NAS £100 WikiSupport

Option [2]
However if you require custom services (Squeeze box, etc) then building your own is a good option:
Some thing based on an atom in a mini-itx form factor like: Jetway JNC92 £105
As much DDR2 memory as allowed (mini-itx often limits to 2GB)
Note: DDR2 is much more power efficient than the original DDR standard.

2GB DDR2 533MHz for the Jetway JNC92 is about £25

A cheap case like this from ebuyer would look reasonable for £25

I also installed Ubuntu on to an 8Gb USB flash drive for about £20. For wear and tear next time I would just use a laptop drive (£35 for a 120 GB or £50 for 320Gb), which could host the always on server parts like websites, torrents, ftp etc. and let the main storage drives spin down. If you are planning on this with only 2 sata sockets available you may want to put the laptop boot drive on a usb interface (£8 ebuyer, cant find summvision device)

I spent about £100 on a Jetway C7 1.2GHz J7F2WE1G2E not realising it could not take the Jetway expansion cards. As they make a very nice 3Socket 1GBit LAN Card. Turning your machine into a low power Gigabit switch as well (if you configure the OS to bridge the interfaces).

Option [3]
A nice alternative to putting together your own itx machine is the BBS2 for around £380 with the 2G RAM upgrade and VAT. Although 1 Drive must be the Operating System and since it uses its own mounting system low power 2.5" laptop drive can not be used for this task. It can then be set up with hardware raid on the remaining 4 channels, but Software raid is pretty good on Linux and Windows Home Server (Apparently)

The only really advantage of this over building your own system is the 5 Drive bays and Shiny case, which comes at a real price. Not forgetting if you built your own itx system you can easily add external usb drive to it, or get it to mount and share additional NAS drives like [1] or put in a large case and get some thing like this 12 port sata controller £600 or a 4 port sata controller £75

Note: The case recommended in [2] only has room for 2 hard drives using Raid1 or adding extra capacity the bootable drive if separate from the storage would have to be external.

Again the drive could be external in [3] if you wanted to use a laptop drive in 3.

Follow Up Post
Why put a Laptop drive in a desktop?

Sunday, 22 March 2009

Ruby finding OS

To find the Operating System that you ruby script/program is running on you can do:

To return one of Windows, Mac, Linux you could do:
if (RUBY_PLATFORM.include? ("darwin"))
os = "Mac"
elsif (RUBY_PLATFORM.include? ("nix"))
os = "Linux"
elsif (RUBY_PLATFORM.include? ("Win"))
os = "Windows"
os = ""

there is also
puts ENV['OS']
but this only works on windows and is empty for Linux and Mac OS X

Saturday, 21 March 2009

Ruby Shoes defining centre point of text

I figured out this method for defining the centre point of a block of text. Actually you define the start and width of a flow element of which text can be centred in.
#Centred Text
@app.flow (:left => 50, :width => 60) {
para ("Centered Text", :align => "center")

Friday, 20 March 2009

Ruby Shoes Tabs Layout

I have just released a very basic framework for putting tabs across the top of a Ruby shoes window.


Ruby Shoes Positioning Text

Ruby Shoes Positioning text and links can be done like this:
@app.para ("Text to Position", :left => 100 )
@app.para (link("main", :click=>"/", :stroke => black), :left => 200 )

Ruby Shoes Link nounderline

I currently find it hard to find short cookbook style examples of Ruby Shoes so I will probably be posting lots of small snippets here for me to refer back to.

First up creating a link for a multipage (not multi-window) application with out the link and black text:
link("main",  :click=>"/",       :stroke => black, :underline => "none")

Thursday, 19 March 2009

Rubys update method

In my last attempt at a config system for ruby GUI apps I wanted to define default values for the preference options, so that if it gets expanded with new values it does not break when used with old config files.

I tried something like:
def loadConfig(configFile)
config = {}
config[:raw_conf_folder_loc] = "1"
config[:drv_conf_folder_loc] = "2"
if File.exist?(configFile)
config = open(configFile) {|f| YAML.load(f) }

This creates a config object (an array of hashes) and assign some values. Then if the config file exists move the pointer to a new object loaded from file, which then leaves the old config object to be picked up by the garbage collector. We are only left with the options in the file defined any defaults set will readback as nil.

To get around this problem I did the following:
def loadConfig(configFile)
if File.exist?(configFile)
config.update(open(configFile) {|f| YAML.load(f) })
#do this to set parameters that might be missing from the yaml file
if config[:raw_conf_folder_loc].nil?
config[:raw_conf_folder_loc] = "1"
if config[:drv_conf_folder_loc].nil?
config[:drv_conf_folder_loc] = "2"
return config

But this is an extra 3 lines per option and looks ugly.
Today I discovered a better way of doing this using the update() method.

def loadConfig(configFile)
config = {}
config[:raw_conf_folder_loc] = "1"
config[:drv_conf_folder_loc] = "2"
if File.exist?(configFile)
config.update(open(configFile) {|f| YAML.load(f) })
return config

Just like the first version but using update() instead of =, this replaces the default values that have been assigned inside the file. Full example ruby_yaml_config.rb

Tuesday, 17 March 2009

A Better Ruby preference system using YAML

An improved preference system for ruby, which can also give an empty string for new values.

Based on this

Lightweight preference system for ruby

I have replace this method with a yaml method

Original Post:
When using GUI applications it is often nice for them top remember some of the settings, here is some snippets of a preferences system:

Near start of ruby app/script
   outputFile = ".photoflow/.photoflowrc"

#Define before opening so new variables are definde empty.
# If undefiened never get added to the config file,
# which is a pain for manual edits.
@raw_conf_folder_loc = ""
@drv_conf_folder_loc = ""

#Loaded Prefs from file
if File.exist?(outputFile)
configfile =, "r")
while (line = configfile.gets)


When any of the user setting are changed call 'createConfig'
 def createConfig(outputFile, raw_conf_folder_loc, drv_conf_folder_loc)
FileUtils.mkdir_p (".photoflow")
## Delete output File if It exists
if File.exists?(outputFile)

outputFileHandler =, File::CREAT|File::WRONLY)
outputFileHandler.puts("\@raw_conf_folder_loc = \"" + raw_conf_folder_loc + "\"")
outputFileHandler.puts("\@drv_conf_folder_loc = \"" + drv_conf_folder_loc + "\"")


I have some problem with the scope of the variables, ideally I would not need to pass them as arguments to the function.

NB: Ruby functions are contained in def's, ie def SomeFunction end

Subversion (SVN) executable properties

When first commiting a file to Subversion the executable property is set (based on the files x property). If script file etc are mistakinly added/commited with this property incorrectly set it has to be manually altered so that they are executable when others check out the repository.

A more complete explanation is given in the link[1] but below is a quick example of how to fix this:

$ ls -l
>-rw-rw-r-- 1 user group 2248 Mar 17 16:45

$ svn propset svn:executable
>property 'svn:executable' set on ''

$ls -l
>-rwxrwxr-x 1 user group 2248 Mar 17 16:45*

To remove an incorrectly set Executable property:
$ svn propdel svn:executable file
>property 'svn:executable' deleted from 'file'

Ruby loops

Incrementing loops in ruby is easy (eamples in ERB)
<% (0...4).each do |i| %>

<%=i%><% end %>
This will output

NB: the '...' mean one less than the number. '..' would out put 0-4

Decrementing loops are a little harder, as low..high numbering is required for the previous format.
<% (4-1).downto(0) do |i| %>

<%=i%><% end %>
This will output

NOTE [29/04/2009]
Because these loops are generated using an iterator you can not just set i to the value you want next, ie to jump a value or increment/decrement in 2's. for this a for/while loop must be used.

<% i=0 %>

<% while (i<8) %>
<% i=i+2
end %>

Decompressing .rar files on Mac OS X

Just found this program seems pretty good so far for extracting rar files on the mac.

unrarx (Free but accept Donations)

Thursday, 12 March 2009

Ruby GUI Development

Just discovered a new and popular GUI Toolkit for use with Ruby. Shoes The second version is codenamed Rasins.

Looks like I might be able to replace Java as my multi OS language for Graphical apps.

The latest (Dec 2011) version is 3.1 codename "Policeman"

Tuesday, 10 March 2009

Tech Groups in Edinburgh

I just found out about these 2 Tech groups in Edinburgh both supported by The University of Edinburgh, Informatics.

Thursday, 5 March 2009

Java multi thread errors

I have been trying to get a seperate thread going to do some background processing in my SourceForge project FileExplorer but after following this tutorial :

I keep getting this error:
Exception in thread "Thread-5" java.lang.IllegalMonitorStateException: current thread not owner at java.lang.Object.wait(Native Method)

Which was caused by:
missing the 'synchronized' keyword from the definition of the methods that call wait() & notify()