Changing the hostname on your raspberry pi

By default, the hostname on a raspberry pi installation will be “raspberrypi”, which is great if you just have the one pi.

Two raspberry pis, one with a BrickPi attached for controlling lego mindstorms
Two raspberry pis, one with a BrickPi attached for controlling lego mindstorms

If you’ve got more than one, then you’re going to get hostname conflicts when you attach both to your network. Fortunately its easy to correct this.

Plug the pi that you want to change hostname onto the network (leave the other unattached). That way when you ssh onto raspberrypi, you know which one it is.

Next, edit the hosts file.

sudo nano /etc/hosts

You’ll need to change the last line to whatever you want to name the pi, in my case I called it robopi       localhost
::1             localhost ip6-localhost ip6-loopback
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters       robopi

Exit that file and then change the hostname file

sudo nano /etc/hostname

Change it to the same name you put in the hosts file


Thats the configuration changes done, next we need to restart the hostname service, but executing:

sudo /etc/init.d/

Then restart the pi

sudo reboot

After that, you should be able to ping and connect to robopi:

Jamess-MacBook-Pro:pi Elsey$ ping robopi
PING robopi.home ( 56 data bytes
64 bytes from icmp_seq=0 ttl=64 time=1.802 ms
64 bytes from icmp_seq=1 ttl=64 time=4.141 ms
--- robopi.home ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.802/2.971/4.141/1.170 ms
Jamess-MacBook-Pro:pi Elsey$ ssh pi@robopi
pi@robopi's password: 
Linux robopi 3.6.11+ #456 PREEMPT Mon May 20 17:42:15 BST 2013 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Dec 29 15:59:40 2013 from unknown
-bash: /etc/profile: is a directory
pi@robopi ~ $ hostname

Thats it, you can connect the original “raspberrypi” to the network, or change the hostname of that too

Recursively deleting .svn directories

Messing around with your subversion directories and fed up of the .svn hidden folders laying around? If you try and checkin some directories that contain a .svn folder from some other repository, you’re going to have a whole world of pain trying to fix it (speaking from first hand experience here)

The easiest way to clear up rogue .svn directories is to run this command (on linux or mac). It will recursively find all directories named .svn, and pass them in for removal.

rm -rf `find . -type d -name .svn`

On a Windows 7 environment, I find the easiest way is to just open Windows Explorer in the root directory that you’re interested in, and search for .svn in the top right hand search bar, then highlight all results for .svn and delete, easy :)

Hope this helps

Using special characters in a linux sed command without having to escaping them

I came across a brilliant little feature of the linux sed command today that I wasn’t aware of, and thought it was well worth posting up about.

I’d been using sed statements inside a bash script, to trawl through property files and replace values, these were all alphanumeric values so I didn’t have any problems with the usual sed comand of

sed -e s/replaceThisValue/withThisValue/g

That worked great, but then I had some properties introduced that contained special characters, notably the forward slash and equals. I scanned the interwebz for answers and there were all sorts of complicated techniques for escaping special characters, passing them into awk and all sorts of other such nonsense, however there is a much simpler way, just use a different separator character.

Put some data into a file…

# this will echo the URL and save it into urls.txt
echo >> urls.txt

Then replace it with the sed command…

# This will replace with
# The bit after the sed is basically a mechanism for updating the original txt file via a tmp file.
sed -e 's=' urls.txt > urls.tmp && mv urls.tmp urls.txt

Since the old/new values above contain forward slashes, I didn’t want to bother escaping them, so I’ve just used an equals character instead of the forward slash to denote the segments of the sed command.

This also works with the at symbol, it may work for others too, but I haven’t tried

# The @ symbol works too!
sed -e 's@' urls.txt > urls.tmp && mv urls.tmp urls.txt

Hope this helps!

Top 10 Techie things I want to achieve in 2012

I’m not the type of person that gets bored easily, I’ve always got many things to keep me amused, mostly side projects at home. I’m a firm believer, that if you don’t set yourself goals in the first place, then you won’t have anything to fail to achieve, so I’ve set myself a list of targets that I’d like to achieve in 2012 knowing full well I probably won’t get around to them all, but if I can do at least 3, it was worth it.


I first picked up the SCJP study guide sometime around 2008, and I’ve had a love-hate relationship ever since. It’s by no means a trivial read, in fact, over 800 pages of solid technical details, a fair chunk of which I’ve never actually used, and probably never will once I’ve got through the exam. Reading the book is not enough to get through the exam, you also need to spend countless hours writing small code snippets to back up understanding, and spend plenty of time in mock exam simulators to prepare yourself. I have a terrible habit of getting obsessively involved in studying for a few weeks, before something pops up (working extra hours on a recent project at work is one good example) and I’ll not touch the book for weeks, only to have to re-cover the chapter where I last left off. This is definitely my goal for 2012, if I achieve nothing else but this, I’d be contempt.

Update AndroidSam

I put my first android app out on the market earlier this year, since its release I’ve had some fantastic feedback, amassing well over 15,000 downloads in the first 6 months alone. The app was very much an experimentation, and I certainly cut a few corners in the UI department prior to launch. I’ve been working on a few look and feel improvements, and a few other tweaks that I’d like to get out there soon.

Become more active on JR and SO, and java black belt

This is a must, theres no end goal and its more of an ongoing task that I must do. StackOverflow is a technical Q&A site, I’ve mostly become involved on the questions asking side, but the site has almost doubled in size in recent years so now there are plenty of unanswered questions that I can sneak in answers to, so I’ll have to start sweeping through my tags and get answering. JavaRanch is also a great site, I read this daily, however I rarely leave any posts. I’m planning to get more active and try to chip in with my comments more often. JavaBlackBelt is yet another great site, I was invited to be a beta question creator on the android exam but I just didn’t get round to providing any content, perhaps I can get more involved in 2012.

Complete SCJP study write ups

I found that a good way to help remember topics when studying, was to try and blog about them. I took the index of the SCJP study guide and outlined all the topics, and then gradually made my way through them all blogging about them in my own words. When trying to explain something, you often realise how you know (or sometimes how well you don’t know a particular subject). I’m about halfway through, and I’d really like to complete the blog posts, and get as much of my sample code up onto my Github account so it can help others.

Read, digest, and blog about technical books

Books, I’ve got a whole shelf of books that need some time. The main 3 that I’m interested in reading in 2012 are Effective Java, Clean Code, and Pragmatic Programmers Guide.

Effective Java is basically a compilation of tips and tricks that a Java developer should use if at all possible, Clean Code tells you how you should be writing your code and approaching problems, and the Pragmatic Programmers Guide is just more theory to lay on top. They’re not trivial reads, and some of it may possibly be too advanced for me, but if I can take anything away from it, it should help my progression.

Finish off my other android projects

I’ve been using Evernote to brain dump app ideas, its a handy little tool. Sometimes you get ideas spring into mind at the most awkward of moments, but most of the time I have my phone to hand, so I just tap them into evernote and let my ideas develop. Right now, in my cooking pot of ideas, I’ve got about 6 apps that I feel are worth putting to code, most are utlitlies but I have a few heavyweight ideas in there. Hopefully I can progress these throughout the year and get at least a few out to market.

Explore Spring Web MVC

The first company that I worked at solely produced Java web applications, that was where I got my first taste for the likes of Struts, Stripes, and a little bit of Spring MVC. I particularly liked working with the Stripes MVC framework, but it did lack a lot of community support, I’d like to explore a little with Spring MVC, since it’s always handy to know how to use the basics of Spring anyway. I started writing my own sales tracking system on Google App Engine, perhaps I’ll do something similar with Spring MVC and host it in the cloud somewhere.

Complete a cloud based CI environment

I’ve got various little side projects on the go, sometimes I use my windows PC at home to work on them, sometimes my works laptop, or my linux machine, so it can be a bit of a pain managing source code and builds. Fortunately I discovered something called Unfuddle, an online SVN repository where I could check my code into. I’ve also discovered something called CloudBees, which is a free on-line Jenkins installation, I’m planning to use that to build all my projects in the cloud, and dump artefacts onto DropBox. I may look at maven repositories too. Ultimately, I want to get my build processes in the cloud, so its purely coding that happens outside the cloud.

Ubuntu Certification

OK so one certification in the year is optomistic, but what about two? I’ve been an on-off linux user since I was in college, only really dipping back into Windows when I go through phases of gaming (WINE is just too much effort). Being competent with the shell terminal is going to help in the long run, so why not dedicate some time to skilling up in something useful. I’m not sure if I’d specifically go for the UCP, but it seemed an obvious choice since I have some familiarity with Ubuntu.

Explore Android ICS

With the latest Ice Cream Sandwich android released, theres plenty to be experimenting with, even if theres only a handful of devices that support it. I imagine that ICS will become more and more supported as the year goes on, so its probably time for me to devote some hours into picking up the new features of the SDK, and coming up with something nice. I’m also desperately in need of upgrading my 2.1 Orange San Francisco sub £100 handset, so possibly an excuse for a nice new shiny upgrade?

Revisit GAE Sales Tracker

About 2 years back I began working on an open source sales tracking system, to monitor progression of sales prospects. I started this in Stripes MVC framework and deployed to the Google App Engine. At the time GAE was still in its infinacy, but after a few years and several upgrades, I think developing on this platform may be slightly less painful now. I still have all the source code, and still have a running demo, maybe I can pick it up again and see what GAE improvements have come around.

FTP: How to download all files, directories and sub-directories

I’ve recently decided to cancel my hosting package with 1and1, as I don’t really have much use for it any more what with all the freebies Google is dishing out.

I needed to take a backup of all my files, and unfortunately mget doesn’t (or at least at the time) doesn’t support the downloading of directories, luckily there is another tool to help, <a href=””>wget</a>.

This example of wget will download all files (the -r specifies recursively) from a directory on the domain

<code>wget -r</code>

Slackware 13.0 Installation : Part 1, pre-install

Slackware, which I like to refer to as “proper linux”, theres no messing around with fancy wizards, this is hardcore linux; and a good cure for insomnia (second to Linux From Scratch that is)

This should help you get Slackware 13 installed, I did all of this using Virtual Box so make sure you have that installed first, and have created an environment ready for slackware.

Insert your LiveCD, or mount your downloaded ISO onto Virtual Box, then start up the virtual machine. Once virtual box has loaded up it should bring you to the first welcome screen in the Slackware 13 installation.

Just press enter at the first screen, as we’re just doing a basic install we won’t need any advanced parameters.

The next prompt you’ll receive, just select to use the default keyboard map.

You will next be presented with some information about how to begin the installation, and be asked to login as root. Go ahead and type root, you’ll then be ready to start installing.