Click Technology

Linux, Windows, Mac it's all good

Which version of Linux am I running?


How many times have I tried to find out _exactly_ which version of Linux I’m running when installing something?  I either get the kernel version (no good for adding debs etc) when I want to find out what the Debian underlying codename is and so on. Here then is the solution. All of it.

uname -a && cat /etc/*release
posted under Linux Tips | Comments Off on Which version of Linux am I running?

Happy Ed Balls day


Happy Ed Balls day

posted under General | Comments Off on Happy Ed Balls day

UK postcode regular expressions


I found these two regexps expressions for UK postcodes today. The first is check if the number and letter sequence is correct. I’ve modified it slightly to look for one or two spaces between the groups of letters and numbers. Worked pretty well under PCRE. Noice. The second regex is to validate the postcode in its entirety. It worked for all the postcodes I had, but this is a constantly changing situation.

Just the basics – format is valid?

Here it is and requires the g(lobal) switch.


Sample data…

UB11 1FW
This is a B73 6AZ postcode
WF16 0HL
London too, EC2A 2BB, nice.
RG21 4EA
BA15 1AJ
AB10 1XL

And a PHP snippet of the above..

    $re = "/([A-Z]{1,2}[0-9][0-9A-Z]?\\s{1,2}?[0-9][A-Z]{2})/"; 
    $str = "BA2 3BH\nUB11 1FW\nCR0 4ZS\nThis is a B73 6AZ postcode\nSW1E 5JD\nLS1 2JZ\nW1W 8AG\nWF16 0HL\nLondon too, EC2A 2BB, nice.\nRG21 4EA\nBA15 1AJ\nCB4 0FW\nEC4M 9HH\nAB10 1XL\nEH2 2BY\nEC4M 9HH\nEH2 2BY"; 
    preg_match_all($re, $str, $matches);

Full Monty – Postcode itself is valid?

This regexp should be able to validate most postcodes. Worked well on all the data I had.


And here then is the code snipped in Python, the most flexible scripting language there is. By far.

    import re
    test_str = u"BA2 3BH\nUB11 1FW\nCR0 4ZS\nB73 6AZ\nSW1E 5JD\nLS1 2JZ\nW1W 8AG\nWF16 0HL\nEC2A 2BB\nRG21 4EA\nBA15 1AJ\nCB4 0FW\nEC4M 9HH\nAB10 1XL\nEH2 2BY\nEC4M 9HH\nEC4M 9HH\nEC4M 9HH\nEH2 2BY\nEH3 7NS\nEH3 7NS\nCB22 3AT\nGU2 7AH\nEC1M 6EH\nRG10 9NN\nSL4 1BE\nKT10 9AD\nW1W 8DH\nBA1 5BB\nTN4 8BS\nCF10 2EH\nCW7 3RT\nW1U 6HP\nEC2N 2AN\nW1W 7PA\nEC3A 7NH\nGU6 8TB\nB60 4JE\nW1S 2LG\nG2 7JS\nRH6 0PA\nWF5 0AN\nHA1 1BQ\nEC2R 7AF\nEC2R 7AF\nEC2R 7AF\nEC2R 7AF\nRG1 1AX\nWC2R 1DJ\nW1J 0DW\n"
    re.findall(p, test_str)

By the way, some awesome regex testing websites are…

posted under Linux Tips | Comments Off on UK postcode regular expressions

IT summarized


I sometimes feel like information technology is just exactly like this.

View post on

There’s loads of great (open source) software out there but connecting it together to streamline it and thence make it really effective is the killer.

posted under General | Comments Off on IT summarized

Create Virtual Disk from physical hardware


This came up the other day, how do you add a disk to VirtualBox that physically exists? E.G. you have created a test vbox and would like to plug in your old laptop hard drive and have a look at the contents..

Here goes..

sudo lsblk

And get the following similar output..

NAME                       MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                          8:0    0 465.8G  0 disk  
|-sda1                       8:1    0   243M  0 part  /boot
|-sda2                       8:2    0     1K  0 part  
|-sda5                       8:5    0 465.4G  0 part  
  +-sda5_crypt (dm-0)      252:0    0 465.4G  0 crypt 
    +-mint--vg-root (dm-1) 252:1    0 465.4G  0 lvm   /
sdb                          8:16   1   7.5G  0 disk  
|-sdb1                       8:17   1   459M  0 part  /media/your-username/usbstick
sdc                          8:32   0 465.8G  0 disk  
|-sdc1                       8:33   0   243M  0 part  
|-sdc2                       8:34   0     1K  0 part  
|-sdc5                       8:37   0 111.6G  0 part  

Examine the tree and find out what your old hardware is called, e.g. /dev/sdc in this case.

Now create a directory for the virtual disk..

mkdir -p /home/your-username-here/VirtualBox/spare_disks

And use vBox’s commandline tools to create the image, changing /dev/sdX for your device location, prolly /dev/sdc.

sudo VBoxManage internalcommands createrawvmdk -filename "/home/your-username-here/VirtualBox/spare_disks/500GB-hard-disk.vmdk" -rawdisk /dev/sdX

Now chown and chmod the varioius relevant locations and that’s it..

sudo chown your-username-here:your-username-here /home/your-username-here/VirtualBox/spare_disks/500GB-hard-disk.vmdk
sudo chmod 777 "/home/your-username-here/VirtualBox/spare_disks/500GB-hard-disk.vmdk"
sudo chmod 777 /dev/sdX

Now open VirtualBox and add in the disk in the usual way (Select your box, then –> settings –> storage –> select disk controller –> click ‘adds hard disk’ icon –> Select vmdk file and that’s it. Fire up your machine and voila, the machine sees the external disk. Nice.

posted under Linux Tips | Comments Off on Create Virtual Disk from physical hardware

Burn an ISO to a USB stick


Every time I want to do this it seems to take waaay longer than it should. Here then, the instructions in n steps under Linux.

sudo lsblk

Check and see which device is your USB stick. In the commands below, the device is listed as /dev/sdaX, but in reality it will be /dev/sdc probably. Be careful. If you mis-select the device you could potentially DESTROY all your data, in which case you will have to go through all five stages of data recovery grief, namely..

Denial = “It wasn’t me

Anger = “How the fuck did I just do that? What was I thinking, cutting and pasting commands off the interwebs??

Bargaining = “If I reboot the machine, the data will probably come back. Actually, thats almost a certainty.

Depression = “Who suggested rebooting? What a stupid idea that was. I’m completely screwed. Why didn’t I do routine backups, especially of my thesis, my research, my entire music collection and all my photos since 2003.

Acceptance = “Either fork out for a data recovery company or start fresh with nothing.

Consider yourself warned. And also, make regular backups.

So, unmount the USB drive in question..

sudo umount /dev/sdX

Format it as FAT32

sudo mkdosfs -n 'usb-bootable' -I /dev/sdX -F 32

Run isohybrid..

sudo isohybrid /home/username/Downloads/systemrescuecd-x86-4.7.1.iso

Now burn the iso image to USB

sudo dd if=/home/username/Downloads/systemrescuecd-x86-4.7.1.iso of=/dev/sdX bs=4k

Flush data to the USB drive..

sudo sync

And eject the USB drive..

sudo eject /dev/sdX

Finished. Your USB pendrive is bootable and ready to go.

posted under Linux Tips | Comments Off on Burn an ISO to a USB stick
« Older EntriesNewer Entries »