May 2nd 2013

Using jQuery in Firefox Extensions

Download jQuery and place it in the chrome/content folder of your Firefox extension. I’m not sure if it’s of any relevance but I’m using Firefox 20.0 and jQuery 1.9.1.

In the same directory, create a test.js file (for calling various jQuery methods). Place the following code inside the file-

	//prevent issues if there are other JQuery instances running
	$whatever = jQuery.noConflict();
 
	//hide all the paragraph tags, to test JQuery
	$whatever("p",window.content.document).hide();

Voilà! It’s possible to access jQuery from a Firefox extension. I haven’t tested this extensively yet, but it’s a proof of concept.

May 1st 2013

Matchbox Twenty, o2 Academy, Glasgow, 21st April 2013

MB 20

I discovered Matchbox Twenty in 2009 (thanks to Spotify) but I wasn’t originally planning on going to this gig. My friend had a spare ticket going and offered it to me. Of course, I can’t refuse the opportunity to go to a rock concert.

We had a leisurely Sunday afternoon drive down to Glasgow, with plenty of time to go shopping and have tea at TGI Fridays. By the time we got back to the o2 Academy, the queue was rather long and the doors were about to open. The building doesn’t look much from the outside (especially since it’s encased in scaffolding at the moment) but it was fine inside. At the merchandise stand, there was option to purchase a live USB. Basically, after the concert, you plug it into your computer and download the soundboard recording of the gig. I think this is a brilliant idea. £25 might seem pricey however, I love having a proper recording of concerts I’ve been at- I wish more artists would do this. It also meant I didn’t have to record my favourite songs during the show- I was free to just enjoy the concert.

Onto the show….First off, there was no support act. Matchbox Twenty came on at 8.30pm and went off stage at 10.50pm, so it was a long concert. Luckily, we managed to get a space at the left-hand side of the stage, 2nd/3rd row. Perfect view!

My highlights-

Disease- great guitar work from Kyle Cook

She’s So Mean, How Far We’ve Come, 3 A.M., Real World- 4 of my favourite songs, played in a row

Unwell- another favourite

Radio/Stay With Me(Faces cover)/So Sad So Lonely- Medley- SO MUCH ENERGY! This whole medley went on for 15 minutes

Don’t You (Forget About Me) (Simple Minds cover)- well this made me feel like I was in a John Hughes movie. I loved it and Rob did an excellent job with it.

Push- again, another of my favourites. Great way to end.

Paul Doucette- very lively guitarist/drummer. I’ve got no idea how he kept that level of energy going for the whole evening. If I played guitar like that, I’d be lucky to last 2 songs.

Great show and I’d jump at the chance to see the band again :)

Setlist
Parade
Bent
Disease
She’s So Mean
How Far We’ve Come
3 A.M.
Real World
Girl Like That
I’ll Believe You When
If You’re Gone
Overjoyed
All Your Reasons
Waiting On A Train
Long Day
I Will
Unwell
Radio/Stay With Me(Faces cover)/So Sad So Lonely- Medley
English Town
The Way
Bright Lights
Sleeping at the Wheel

Encore:
Our Song
Back 2 Good
Hang/Peaceful Easy Feeling (Eagles cover)- Medley
How Long
Don’t You (Forget About Me) (Simple Minds cover)
Push

January 14th 2013

Wireless Printing/AirPrint Server via the Raspberry Pi

One of the first projects I wanted to attempt when I got my Raspberry Pi was to turn my wired Canon printer into a wireless printer. I managed to get it working so I thought I’d share the steps I went through.

Right, first things first, update the packages on your Pi:

	sudo apt-get update

Next up, install all the packages required for printing. The following commands could be put on one line but I took the longer option of installing one package at a time.

	sudo apt-get install avahi-daemon
	sudo apt-get install avahi-discover
	sudo apt-get install libnss-mdns
	sudo apt-get install cups
	sudo apt-get install cups-pdf
	sudo apt-get install python-cups

It takes a while for the packages to install, so grab a cup of tea while you wait. Once everything has finished, you’ll need to add your username to the CUPS server so you’re able to add printers etc later on.

	sudo usermod -aG lpadmin pi

Now, check that CUPS has installed correctly and that the service works (it stands for Common Unix Printing System and will let the Raspberry Pi act as a print server):

	sudo /etc/init.d/cups start

You’ll need to check the Avahi service works too (it finds various devices on the network which are discoverable):

	sudo /etc/init.d/avahi-daemon start

Next, you’ll need to edit the CUPS config file:

	sudo nano /etc/cups/cupsd.conf

You’ll need to set-up the port we’re going to be listening on. Comment out the line that reads “Listen localhost:631″. Add in “Port 631″. It should look something like this:

	#Listen localhost:631
	Port 631

CUPS will need to be told to be used with any hostname, so it can work with AirPrint. The ServerAlias * directive needs to be added before the first occurence of <Location />

The config file will also need to be edited to control access to the server by adding “Allow @Local” in several places e.g.:

	# Restrict access to the server...
 
  		Order allow,deny
  		Allow @Local

You need to include it in these areas of the config file:

	# Restrict access to the server...
	# Restrict access to the admin pages...
	# Restrict access to configuration files...

Save the config file and restart the CUPS service:

	sudo /etc/init.d/cups restart

Now, find the IP address of your Pi. It’ll be something like 192.168.1.x

	ifconfig

Navigate the the CUPS configuration page by typing the IP address you just retrieved and the port number CUPS uses (so it’ll be an address like 192.168.1.x:631). A security exception message may pop up but that’s ok. Continue onwards!

Click on the Admin tab and view the server settings which are towards the right-hand side of the screen. Tick the box that says “share printers connected to this system”. At this stage, you’ll be asked for the username and password of the Raspberry Pi.

Plug your printer into one of the USB ports on the Pi. Click “add printer” in the CUPS web interface and it should appear under local printers. You’ll have to fill in details for the printer, such as name and location. You can enter whatever you want in here but the important part is ensuring you tick the “share this printer” box. Following this, you’ll have to select the appropriate printer driver from a (large) list that appears. Enter print and paper settings too. You’re now ready to click on maintenance > print test page. If everything has gone to plan, the test page will print successfully. You’re not done yet though….

You now need to set-up the Avahi service which will allow you to discover wireless printers on Apple devices. First, navigate to the opt directory, make a directory called airprint and move to it:

	cd ../../opt
	sudo mkdir airprint
	cd airprint

Now, download the Python file which will help us generate the services we need:

	sudo wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py

The permissions of the script need to be edited so it can be executed:

	sudo chmod 755 airprint-generate.py

Generate the Avahi service and place the script in the appropriate folder:

	sudo ./airprint-generate.py -d /etc/avahi/services

On generating the service I got the error shown below. This is fine if you don’t have any Apple devices running iOS6 but I’m willing to bet that most people with capable devices are running it.

	image/urf is not in mime types, what_the_printer_is_called may not be available on ios6 (see https://github.com/tjfontaine/airprint-generate/issues/5)

To fix this issue, you’ll have to create 2 files in the /usr/share/cups/mime directory. These files will be called airprint.types and airprint.convs. Let’s start with airprint.types.

Use nano to create a new file and edit it:

	sudo nano airprint.types

Insert the following into the airprint.types file:

	#
	# "$Id: $"
	#
	# AirPrint type
	image/urf urf string(0,UNIRAST)
	#
	# End of "$Id: $".
	#

Again, use nano to create the second file:

	sudo nano airprint.convs

Insert the following into airprint.convs

	#
	# "$Id: $"
	#
	# AirPrint
	# Updated list with minimal set 25 Sept
	image/urf application/pdf 100 pdftoraster
	#
	# End of "$Id: $".
	#

Restart the CUPS service now that changes have been made:

	sudo service cups restart

The Python file which helped us generate services earlier needs to be re-downloaded to the opt/airprint directory

	sudo wget https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py

Ensure that you’re in the airprint directory and regenerate the Avahi service (like before):

	sudo ./airprint-generate.py -d /etc/avahi/services

Various files have been edited so I’d recommend that you reboot the Raspberry Pi around now. If you only have Apple devices, that’s it, you’re done- hopefully, everything should work. In my experience, I’ve found that the printer can be a little laggy and sometimes, it just doesn’t bother printing certain jobs from my iPhone. Don’t let that put you off though- most of the time it works as expected. I’ve had no problems printing from my laptop or iPad.

 

INTERMISSION

 

Now, I’m aware some of you will want to use the Raspberry Pi to print from Windows machine. If you want to do this, you’ve got a few more steps to go. Before I go any further, I’ll say that I tested this with Windows XP only- things might be easier with Windows Vista/7/8. Maybe things will need to be done slightly differently, I don’t know.

Install Samba on the Raspberry Pi which allows cross-platform file/printer sharing (basically allows Linux and Windows file systems to connect to each other)

	sudo apt-get install samba

Navigate to the samba config file which can be found at- /etc/samba/smb.conf. Ensure it contains the following data:

	# CUPS printing.  See also the cupsaddsmb(8) manpage in the
	# cupsys-client package.
	   printing = cups
	   printcap name = cups
	[printers]
	   comment = All Printers
	   browseable = no
	   path = /var/spool/samba
	   printable = yes
	   guest ok = yes
	   read only = yes
	   create mask = 0700
 
	# Windows clients look for this share name as a source of downloadable
	# printer drivers
	[print$]
	   comment = Printer Drivers
	   path = /usr/share/cups/drivers
	   browseable = yes
	   read only = yes
	   guest ok = no

 

INTERMISSION

 

You’re now finished with the Raspberry Pi. Again, I’d reboot it anyway, just to ensure that all appropriate files are running with the configuration that you’ve entered.

So, you want to print in Windows, eh? Here it goes-

I’ll reiterate, I used Windows XP. Things might be different in Vista/7/8

Install the drivers for your printer

Navigate to My Computer > View workgroup computers > Raspberrypi server > Printername

A few dialogue boxes may appear but they should be ok

Select the appropriate driver from the list of printer drivers that appears and click ok

The printer attached to the Raspberry Pi will now appear in the control panel under printers and faxes

My printer constantly displays “access denied, unable to connect” but it still works anyway (I’ve got no idea why)

Finally, try and print something- the new printer will appear in the list of available printers. Fingers crossed, you should now be able to print from Windows too!

This tutorial is based on content from a few other sources:
Configuring the Raspberry Pi as an AirPrint Server
iOS6 Doesn’t Recognise CUPS Print Shares
Printserver for Windows Clients

December 30th 2012

Setting up an SD card for the Raspberry Pi using a Mac

I had a few issues setting up the SD card for my Raspberry Pi. The main problem I had was that the operating system didn’t make full use of the capacity of the SD card. I thought I’d share the steps I used to get it to work.

Before I go any further, I’d like to note that it was a Kingston SDHC 16GB Class 4 SD card that I used- plenty of storage there and it seems to work perfectly with the Pi. My main computer is a Mac so that’s what I used for transferring the operating system onto the SD card.

Steps for getting the operating system onto the SD card (Mac users)-

  1. Download the Raspbian “wheezy” image from the downloads section of the Raspberry Pi site. Personally, I went with the .zip file which I downloaded to the Desktop and extracted.
  2. Insert your SD card into your computer/laptop. Click on the Apple logo in the top left-hand corner of the screen. Then click “about this Mac” > “more info” > “system report” > “card reader” and find the entry listed as “BSD name”. This will have disk and a number next to it (in my case it was disk2s1- I’ll stick with this example).
  3. Open up the Terminal. This can be found under “applications” > “utilities”
  4. Enter:
    sudo diskutil unmount /dev/disk2s1
  5. If this doesn’t work, try:
    sudo diskutil unmountDisk /dev/disk2s1
  6. One the card has unmounted, enter:
    sudo dd bs=1m if=path/to/where/you/downloaded/the/image/2012-12-16-wheezy-raspbian.img of=/dev/rdisk2

    Remember, in the “of” section of the command, remember to put the disk number of your own SD card. Also, you need to prefix “disk” with “r” so it becomes “rdisk”. Just be careful during this step- you don’t want to get the disk number wrong and accidentally overwrite the operating system on your Mac- double-check you’ve done it right!

  7. While it’s copying the image to the SD card, the Terminal won’t provide you with any progress information. Instead it’ll just show a blinking cursor. Be patient! In fact, now would be a good time to grab a cup of tea.
  8. When it’s done, the Terminal will just show the usual comand prompt along the lines of:
    computername:~ username$
  9. You’re not quite done yet- you need to eject the SD card:
    sudo diskutil eject /dev/rdisk2
  10. Previously at this stage I inserted the card and started using the Pi which quickly ran out of space. I was puzzled, as I couldn’t possibly have filled a 16GB SD card by installing some Bluetooth tools and gedit. It turns out I’d missed an important step allowing the Pi to utilise the full size of the card. Read on…
  11. Insert the SD card into the Raspberry Pi. This next bit is definitely easier with a monitor so I recommend you connect the Pi into one temporarily (along with a keyboard) and switch it on.
  12. You will be asked to log in once it’s booted. Your username is “pi” and the password is “raspberry”.
  13. Enter:
    raspi-config

    This presents you with a menu. Choose “expand_rootfs” and confirm the changes. Exit the menu.

  14. The machine needs to be rebooted. Enter:
    sudo reboot
  15. The Pi will reboot and will start sorting out the size of the root partition, enabling you to use the full size of the SD card. This can take a bit of time so grab another cup of tea. Now for the reason I mentioned plugging it into a monitor while it’s resizing the partition- I tried to do this via ssh from the Mac. I couldn’t log in while it was resizing so I assumed something had gone wrong. In fact, it was doing exactly as I had asked it to do- I just couldn’t see it. If you have a monitor plugged in, it constantly tells you that it’s resizing the partition until it’s finished.
  16. When the Pi has finished resizing the root partition, you’re free to use it! That’s it (well unless you want to play around with the rest of the config options, but I’m not going to cover that)!
December 29th 2012

Raspberry Pi!

Raspberry Pi Logo

First off, I should say greetings and happy holidays folks! It seems I’ve been good this year as Santa brought me a Raspberry Pi (model B- 512MB RAM). For those that are confused, it’s not an edible pie- that would be ridiculous. I’d prefer a strawberry pie anyway. No, it’s a tiny little computer. According to the Raspberry Pi FAQ, it’s described as “a credit-card sized computer that plugs into your TV and a keyboard. It’s a capable little PC which can be used for many of the things that your desktop PC does, like spreadsheets, word-processing and games. It also plays high-definition video.”.

Why did I want a Pi then? Well, I’d like to get to grips with Linux. Every year for the past 5 years, I’ve installed Linux on a machine and declared that I was going to use it as my main operating system. Generally it lasted for all of 2 days before I reverted back to Windows (or for the last few years, OS X). The Raspberry Pi gives me no excuse and offers me a chance to work with the command line. Also (as I’m sure you all know), I’m a massive nerd and I wanted a new geek toy to play with.

To get the Pi up and running as a desktop computer, you need to plug in a USB mouse and keyboard, a power supply, a monitor, a HDMI cable, an Ethernet cable and an SD card to provide the memory. I had all of the above apart from a monitor so I chose to run the Pi “headless”- basically, I accessed it via SSH from the terminal on my laptop. I have plugged it into the tv downstairs though and I’m very impressed- it looks fantastic.

I’ve been busy playing around with it since the 25th and so far, I’ve turned it into a print server (because when I bought my printer, I didn’t think about getting a wireless one). I’m going to detail how I did it in a separate blog post. I can’t wait to try some other projects on it- I love it!

If you want to know more about the Raspberry Pi, pop over to the website or have a look through the FAQs. Alternatively, check out the forums- there’s a bustling community of folks willing to help each other out.

Raspberry Pi is a trademark of the Raspberry Pi Foundation.