Ubuntu Wallpapers

This gallery contains 3 photos.

Lummie’s Wallpapers by Matt Harrison are licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Based on a work at lummie.co.uk. All of these images have been created / photographed by myself.  If you have chosen to use any of … Continue reading

Wallpapers Nov 2010

This gallery contains 59 photos.

Lummie’s Wallpapers by Matt Harrison are licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Based on a work at lummie.co.uk. All of these images have been created / photographed by myself.  If you have chosen to use any of … Continue reading

JQuery and human readable email addresses

Ive just started playing with the power that is Jquery and came up with this nice use for the Ajax functionality in Jquery. You want to put your email address on your web site so people can contact you, but don’t want to put a mailto: anchor in the html, because it will be spidered and added to some morons Spam list. Here is a simple and server independent solution: Firstly, create a file on your site, it doesn’t have to have a html extension, e.g. email.me In the content of the file, add the html snippet that you would like to display to the user as your email address (usually an anchor tag with a mailto: href). This is the html that will be inserted into your web page when the user clicks on the Show email address text. e.g.
<a href="mailto:someone@somewhere">someone@somewhere</a>
In your web pages, where you wish someone to be able to see your email address by clicking, enter a span with a class of email.
<span class="email">Click to see email</span>
in the ready function for your document enter the following:
$('.email').click(function(el){
    $(this).hide().load('email.me').fadeIn(1000);
});
This will add a click function to all elements assigned the email class, that when clicked, will replace the current content with the content of the email.me file (faded in ). In this case your email mailto anchor. This principle can be used to display any content. Maybe you want to hide the comment form for your blog, until a display has been clicked, give it a try.
Demo:
Posted in Javascript | Tagged | Comments Off

OverlayIcon – Displaying overlayed icons in JTree

In companion to the CompoundIcon article, here is a class to allow you to build up icons with overlays that can be used anywhere, but specifically in JTree.
/*
 * (c)2008 mharrison
 * This class is released under GPLv3
 */
package uk.co.lummie.code;
import java.awt.Component;
import java.awt.Graphics;
import java.util.Vector;
import javax.swing.Icon;
 
public class OverlayedIcon implements Icon {
 
    private Vector _icons = new Vector();
    private int _spaceSize = 2;
 
    public OverlayedIcon(Icon[] icons) {
        for (int i = 0; i &lt; icons.length; i++) {
            _icons.add(icons[i]);
        }
    }
 
    @Override
    public int getIconHeight() {
        int result = 0;
        for (Icon icon : getIcons()) {
            result = Math.max(result, icon.getIconHeight());
        }
        return result;
    }
 
    @Override
    public int getIconWidth() {
        int result = 0;
        for (Icon icon : getIcons()) {
            result = Math.max(result, icon.getIconWidth());
        }
        return result;
    }
 
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        int h = getIconHeight();
        int w = getIconWidth();
 
        for (Icon icon : getIcons()) {
            icon.paintIcon(c, g, x + (w - icon.getIconWidth()) / 2, y + (h - icon.getIconHeight()) / 2);
        }
    }
 
    public int getSpaceSize() {
        return _spaceSize;
    }
 
    public void setSpaceSize(int spaceSize) {
        this._spaceSize = spaceSize;
    }
 
    public void add(Icon icon) {
        _icons.add(icon);
    }
 
    public Vector getIcons() {
        return _icons;
    }
}
Posted in Java | Tagged , | Comments Off

CompoundIcon – Displaying more than one icon in JTree

I came across the requirement to display more than one Icon against the nodes in a Jtree. After several hours /days of building custom TreeCellRenderers and TreeCellEditors, inspiration hit. The JLabel can only display one icon, so lets override Icon to display more than one icon, but pretend it’s just a single Icon still. The following Java class implements a CompoundIcon. Simply create an instance of it passing in the array of Icons you wish to be displayed. Use setSpaceSize to change the space between the icons when the are rendered. Use add, to append new icons if needed after the class has been constructed. The instance can then be used wherever and Icon is needed.
/*
 * (c)2008 mharrison
 * This class is released under GPLv3
 */
package uk.co.lummie.code;
 
import java.awt.Component;
import java.awt.Graphics;
import java.util.Vector;
import javax.swing.Icon;
 
public class CompoundIcon implements Icon {
 
    private Vector _icons = new Vector();
    private int _spaceSize = 2;
 
    public CompoundIcon(Icon[] icons) {
        for (int i = 0; i &lt; icons.length; i++) {
            _icons.add(icons[i]);
        }
    }
 
    @Override
    public int getIconHeight() {
        int result = 0;
        for (Icon icon : getIcons()) {
            result = Math.max(result, icon.getIconHeight());
        }
        return result;
    }
 
    @Override
    public int getIconWidth() {
        int result = 0;
        for (Icon icon : getIcons()) {
            result += icon.getIconWidth();
            result += getSpaceSize();
        }
        return result;
    }
 
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        int h = getIconHeight();
        int offset = 0;
 
        for (Icon icon : getIcons()) {
            icon.paintIcon(c, g, x + offset, y + (h - icon.getIconHeight()) / 2);
            offset += icon.getIconWidth();
            offset += getSpaceSize();
        }
    }
 
    public int getSpaceSize() {
        return _spaceSize;
    }
 
    public void setSpaceSize(int spaceSize) {
        this._spaceSize = spaceSize;
    }
 
    public void add(Icon icon) {
        _icons.add(icon);
    }
 
    public Vector getIcons() {
        return _icons;
    }
}
Posted in Java | Tagged , | Comments Off

Having a bit of a late spring clean….

Sorry for any inconvenience, but I'm having a bit of a re-vamp spring clean of lummie.co.uk at the moment.  Normal service will be resumed soon.
Posted in Misc | Comments Off

Ubuntu Server-Setting up and managing Raid1

In preparation for getting my Tranquil PC BBS2, on which I plan to install Ubuntu server on the “OS disk” and have initially two 1TB drives in Raid1 configuration and add an additional 2 later as my storage needs increase, I decided to investigate how to install and configure the raid in such a configuration. Note: In my configuration, I am setting up a NAS / Home server, I have a single drive for the OS that is not raided as I don’t mind having to re-install the OS if that drive fails. (Which I will test in the near future that I can re-add an existing raid to a new install) The Raided drives are the drives that will store the data shared on the NAS. I did the test using Virtualbox, creating an OS virtual disk and 2 virtual disks for the raid. I initially only mounted the OS disk and performed an usual So with ubuntu installed, and the two drives to be raided added to the vm: All the following commands should be run with sudo or as root.

Creating the Raid array

First we need to install mdadm (I think it means mutli-disk admin), the utility for managing the raid arrays. Unfortunately, when I tried the expected sudo apt-get install mdadm, there were some weird package dependencies (known issue) that also install citadel-server, which prompts for loads of unexpected configuration. To get round this, do a download-only of mdadm then run the install with dpkg.
sudo apt-get --download-only --yes install mdadm
sudo dpkg --install /var/cache/apt/archives/mdadm_2.6.7...deb
For each drive in your raid array, run fdisk or cfdisk and create a primary partition that uses the whole drive. These partitions should be the same size. If not the smallest size will be used for the size of the raid array. The partition type needs to be set to type ‘fd‘ – Auto raid – Linux.
fdisk /dev/sdb
Next, run mdadm to create a raid device (/dev/md0 (thats md followed by Zero) you have to call it mdX where X is an md device not in use) we set the raid level to raid1 (mirroring) and the number or devices to be included in the raid to 2 followed by a list of the disk partitions to be used.
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
The raid array will be created and you can monitor it’s progress by typing:
watch cat /proc/mdstat
Once complete, we now have a single device that can be mounted, however, it does not yet have a file system on it. I chose to format it as an ext3 fs.
mkfs -t ext3 /dev/md0
create a folder to mount the device in, I chose /raid , and mount it:
mkdir /raid
mount /dev/md0 /raid
The raid drive is now mounted and available. To get it to be mounted at system startup, we need to add an entry into the fstab.
nano /etc/fstab
add
/dev/md0           /raid          auto     defaults        0      0
reboot and all should be working.

Examining the state of the Raid

Whilst the raid is performing operations such as initialising you can see the status with:
cat /proc/mdstat
mdadm can also be used to examine a hard disk partition and return any raid state information including failed devices, etc.
mdadm --examine /dev/sdb1

Breaking the Array (Replacing a drive)

Building a raid array and not testing it, let alone not knowing how to fix it should a drive go fault is just stupid, so I decided to put the array through it’s paces using the wonderful VirtualBox. So, I shut the machine down and removed the second raid drive from the VM, sdc. During boot-up I noticed a [Fail] on the mounting file systems and after logging in, the /raid mount was not available. This was my first surprise, I expected as on drive of the array was still plugged in and available, that the device would just be mounted with some form of notification of the raid not being correct. I have not investigated if changing the mount options in fstab would enable this yet, so if you know please comment. So after logging in the raid device had been stopped, so I tried running it:
mdadm --manage -R /dev/md0
This was successful, and I could even mount the raid device and access the files on it, however it is running with only one drive now. So, I shut down the VM and created a brand new disk in VirtualBox, and added it to the VM, emulating me replacing the drive with a new one. Started the machine up, logged in and ran mdadm as above to start the array. Faulty devices can be removed with the following command replacing sdc1 with the partition to remove.
mdadm /dev/md0 -r /dev/sdc1
However, as I had removed the physical VM drive (a bit oxymoronic I know) the device was not classed as part of the array, so now I had to prepare the new drive ready for addition to the array. So create a primary partition of the required size on the new drive using fdisk. We don’t need to format it, as as soon as we add it to the array, the existing drives contents will be replicated.
mdadm --manage --add /dev/md0 /dev/sdc1
Run watch cat /proc/mdstat to see it re-building the array I am now going to have a play with extending the array and seeing if I can start off with a raid5 two drive mode, if that can mirror until I add a 3rd and 4th drive then that migh mean a change in my approach for extending the storage in the future. Hope this all helps some other relative newbies to ubuntu and raid.
Posted in Hardware, Software, Ubuntu | Tagged , | Comments Off

Getting the power button on the BBS2 to shutdown ubuntu

Nice and simple:
sudo apt-get install acpid
Posted in Hardware, Ubuntu | Tagged , , | Comments Off

The most TOP utilities for Ubuntu Server

I know this will apply to various linux distros, but continuing the theme of blogs about installing Ubuntu Server on my BBS2, I give you some Top hints for some Top utilities on the command line.
  • top – You most probably already know that running ‘top’ will show you a list of processes and you can see their cpu usage alongside the total cpu usage.  If you press 1, and you have multiple processors it will break down the stats by processor.
  • iotop – You’ll probably have to apt-get install iotop, this little utility shows you the top disk i/o processes detailing the transfer read and write rates.
  • iftop – You’ll probably have to apt-get install iftop, this one shows you the network useage, nicely broken down by destination, sent / received with totals etc.
So think of these Top utilites next time you need to monitor your server in ubuntu.
Posted in Software, Ubuntu | Tagged | Comments Off