Author Archive

Can’t create thread (11) (ThreadError) in Ruby

I have been working on some networked code in Ruby which uses EventMachine. This is part of my work as a Research Associate at the University of Birmingham. I recently had a headache with threading/processes whereby I would get this error during thread creation:

Here is the code I was running:

I knew I wasn’t creating too many threads and I knew I wasn’t running out of memory. After some serious digging, and two hundred browser tabs later,  I found the reason: zombie/defunct processes.

The ’11’ in the error code is actually not from Ruby at all, but from the  pthread class which is used to create new threads in Linux (among other OSes). This is the numerical value for the error code EAGAIN, returned by the function pthread_create, which occurs when:

Insufficient resources to create another thread, or a system-imposed limit on the number of threads was encountered

I had used Ruby’s Thread.list.size to ensure I wasn’t using too many threads, so what could it be?

Continue reading »

Compile GTK+ code with Cygwin Tutorial

To compile code with GTK+ in Windows, the recommended toolchain is MinGW (for a variety of reasons). However, if you want to use Cygwin anyway here is some guidance, which may save you some searching time and head-scratching.

I’ll assume:

  • You have Cygwin installed and you know how to use it
  • You have gcc installed within Cygwin
  • You know how to add entries to the system PATH safely

(Note before we start that it may be possible to so some of this from Cygwin’s installer but I found that manual setup was easier)

Step 1

Download the ‘all-in-one bundle’ from the GTK+ download page and unzip it to your preferred installation directory, e.g. C:/gtk . This is the example directory I’ll use below.

Step 2

Set your system variables:

  • Add the ‘bin’ directory to your system PATH (e.g. C:/gtk/bin )
  • Add a variable called GTK_BASEPATH  with the value of the installation directory (e.g. C:/gtk )
  • Add a variable called LIB  with the value of the ‘lib’ subdirectory (e.g.   C:/gtk/lib )
  • Add a variable called PKG_CONFIG_PATH  with the value of the pkgconfig directory (e.g. C:/gtk/lib/pkconfig )

Note that these can also be done on the Cygwin command line or in your bash profile using ‘export’, e.g.

Continue reading »

Running Gnuplot as a live graph, with automatic updates

I am working on some GPU-based software whose output I would like to visualise with a graph or two, and thought Gnuplot would do the job. Being able to watch the graph change as the program ran would be much better than plotting after all the data to be produced. Unfortunately, Gnuplot cannot be fed data from its standard-in, only commands.

Gnuplot Live Update

After a bit of looking around I found a Perl script that allows live updating. However, this is a bit more heavy-duty than I would like. Indeed, there is a much simpler way of getting live updates on a graph.

Gnuplot has some useful commands we can use:

These are fairly self-explanatory, so let’s make a Gnuplot file, liveplot.gnu, that refreshes itself once every second.

We set the bounds of our graph, then plot the data from the file. using 1:2  means plot columns 1 and 2 as x and y, respectively. with lines  means that the points are joined together rather than plotted separately. We pause for 1 second and then reread, meaning that the command file is re-executed.

To test this, we can write to the file plot.dat  over time and watch the graph update live. Here is a sample bash script to do that:

The function writedata  writes the data points for a basic quadratic graph, y=x^2, where the x and y values are separated. The function sleeps for a second after writing every line. The function writedata  is executed in the background and the Gnuplot script we wrote above is launched.

When this bash script is launched in the same directory as liveplot.gnu as above, the graph can be seen to be generated in real time.

Four seconds left to live – what went through my mind

A few months ago I travelled across England and then across France with my girlfriend, Stephanie, and her parents to move her stuff to Poitiers in western France, where she is studying for a year. After offloading Stephanie’s things and spending a weekend in Poitiers, we had completed most of our 9-hour journey back and were about 90 minutes away from home.

Driving along on the M2 at 70mph while chit-chatting, we noticed a black Mini Cooper ahead with its hazard lights on and not moving at all. It was in our lane, which was the third of four lanes (next to the fast lane) and there was too much traffic to swerve to either side, so we braked firmly and stopped about two metres short of the car in front. The panic of sitting still on a motorway full of very fast-moving cars set in quickly and we put our hazard lights on and looked around to see if we could pull out into either of the adjacent lanes, but the traffic was too heavy and moved too quickly to risk such a move.

I turned around, looking out of the back window to see a car approaching us at high speed and swerving into the lane to the left. Another car approached, but while still far away it moved into the lane to our right. Then, in the distance, I could see a red car approaching and not swerving away like the others. In fact, it wasn’t slowing down at all. I said, “There’s another car coming towards us,” and, while still staring intently for signs of slowing down, screamed, “It’s still coming. It’s not going to stop!

When I said that, I knew we were all going to die.

Continue reading »

How to stop the throttling on your Virgin Media broadband connection

Last year I started using broadband supplied by Virgin Media, which ran on a cabled connection (not the phone line).

I noticed that when I downloaded anything that initiated many connections (such as with a download manager, or torrents), the overall connection speed was very low. This was frustrating because we had an excellent connection, and I could get the full connection speed if I downloaded from a server.

Continue reading »

Enabling command history in terminal programs like Sicstus

When you get used to pressing the up arrow for history items, the tab auto-complete feature and other handy features in the Linux terminal, it can be irritating when the occasional program behaves differently.

I have been using SICStus Prolog for my CS Prolog course and have been irritated by SICStus picking up the up arrow key as ^[[A and not retrieving the last thing I typed.

To get it to work like the Bash shell and other programs do, you can use rlwrap [program].

This program allows you to ‘wrap’ a program you’re running, like SICStus, in the readline attribute. This contains the features you’re used to. Just type something like this at the terminal, e.g.

It will ‘wrap’ your program in the readline function and work as expected. Voila!

If you want more information on rlwrap, check out the man (manual) page.

Snippets – Part I

Over the years, I have collected many screenshots of funny things I’ve seen online, conversations I’ve had, weird Facebook posts and comments, etc.

I thought I might start sharing some on this blog. So here is the first snippet of many (hopefully):


Conversation with a friend on MSN

First line disappears from Eclipse console output

I was just running a standard Java file straight from Eclipse when I noticed something strange. The first line of output was not showing at all.

My code ran an analysis, got back a result and printed a couple of attributes from the result. I was getting all but the first line of output (even though I knew there was nothing wrong with the System.out.println code).

When I ran it in the terminal, I found a few hundred (or thousand) lines of debug output from the analyser which I had forgotten to disable. For some reason, Eclipse was ignoring this and only printing the remaining output. This consumed the first line too, for some reason.

As soon as I disabled the debug output from the analysis code, the output was behaving normally again.

Applying for an IBM industrial placement – a complete guide

This is for anybody applying for an industrial placement during their ‘sandwich year’ at IBM. It should hopefully provide insight for anybody hoping to work for IBM for that year from somebody who went through the process.

My particular placement is in Software Development, but I shall try to make this post general and about all of IBM’s placements.

NB: This article is entirely my own and does not reflect the opinions of IBM.



The IBM Industrial Placement Scheme employs students expecting 2:1 classifications for their degrees during their ‘sandwich year’. This year goes between your 2nd and 3rd years, meaning that if you have a three-year degree, it becomes four-year degree.



You work for IBM for exactly one year, usually starting between July and September. They pay you £15,000 for the year before tax, as well as a £1,000 sign-on bonus which is paid in three parts by being added on to your first three months’ salary payments. If you stop working for IBM any time before you complete three months, the bonus money has to be given back.

If this is your only job, you will be paid and taxed as follows:

£15,000 salary + £1,000 bonus

For the tax year 2011/2012, the income tax-free allowance is £7,475, meaning this is how much of your salary is not income taxed at all. The rest of your salary is taxed at 20%.

So £7,475 + ( £8,525 x 0.8 ) = £14,295 for the year, including bonus.

Hang on, though. You still have to pay National Insurance (for state pension contribution). This is taxed at 11% of anything over £110 per week. At £16,000, the weekly salary works out at £16,000 / 52 = £307.69 per week.

So you are charged 11% of £307.69 – £110 per week, which is 11% of £197.69. This works out to £21.75 per week of National Insurance, which makes a total of £21.75 * 52 = £1130.80 of National Insurance to pay for the year. This makes your after-income-tax salary

Overall, then, you are paid:

£16,000 before tax.

£14,295 after income tax.

£13,164 for the year into your account.



IBM have 26 locations in the UK, but only a few are likely to be taking Industrial Trainees. All Software Development students are placed at Hursley, where IBM’s Software Development labs in the UK are located.

When you attend the assessment centre, you are given a sheet of paper with about ten UK regions and told to tick the ones you are willing to work at. Note that Software Development students have no choice as Hursley is the only place they can go.


Recruitment Process

The recruitment process for IBM is fairly simple. I’ll take you through what I experienced as you are likely to go through (mostly) the same thing.

  1. Visit the Apply page to download  a CV template. You do not submit your own CV but use IBM’s supplement, which is more like an application form.
  2. Fill in the CV template with relevant information. Try to use many examples in your descriptions — asserting that you are good at something means nothing without examples of ways you have demonstrated it in the past.
  3. Click the relevant ‘Apply Now’ link on the apply page to go through IBM’s recruitment pages. Fill in their forms, make sure all details are filled in (some people delay their forms by weeks due to missed out information like degree predictions, etc.) and that you upload your CV template.
  4. Once you receive a confirmation that your form was submitted, just wait.
  5. Soon, you should receive news about the next stage. If you are successful in the application form stage, you will hear from them about the Online Aptitude Test (IPATO). Since I completed my form early, I received this email within 10 days, but know people who received it after a month. Be patient.
  6. Within a couple of days of completing the aptitude test, you should receive news about whether you passed it. Information about the aptitude test is below.
  7. If you passed the test, you should be invited to an assessment centre. I received my invitation three minutes after the email about passing the test. Make sure to respond to the email to confirm your attendance. Information about the assessment centre is below.
  8. If you pass the assessment centre, you will receive an email within a few days telling you that you are in the matching process. This usually means you are accepted into IBM as an employee if they can find you somewhere to work. Information on matching is below.
  9. Once you are matched, you receive an informal job offer. This was on the phone for me. I accepted my offer at the time, but if you have other job applications and want to wait, I have heard there is a deadline of a few days for the decision.
  10. Once you accept the job offer, you will receive a set of documents by email about your job offer. The most important of these is your offer letter. This states when you start, who your manager will be, what their phone number is and other details about your job. At the bottom, it lists paperwork that must be completed and sent back to IBM.

This is mostly it. After this, your main task is to sort out your paperwork, have a chat with your manager to find out what you’ll be doing and do some research. Joining the Facebook group for the year’s Industrial Placement is always a good idea. It’s usually named ‘IBM Industrial Placement 2011/2012′ or similar, and only those who have an offer are allowed to join.


Aptitude (IPATO) Test

This is nothing to worry about if you are technically minded. No matter what you do, you cannot prepare for it, so honestly don’t waste your time trying.

Aside from being able to think logically and technically, the key to doing well in this is concentration. Make sure you have plenty of energy, you are very awake, you’ve had some cold water and that there are no sounds or distractions around you.

Furthermore, you are given another similar test at the assessment centre to make sure you did it, so cheating is both silly and infeasible.

Follow the instructions well and make sure you have pen and paper to hand, as well as a calculator. The questions are mostly to do with rearranging elements on a screen, identifying patterns and performing simple arithmetic calculations on simple ‘real life’ situations. Nothing more than GCSE maths is required, but perhaps brushing up on percentages and similar basic concepts would come in handy.

You are given a chance to complete an example test before the real one which should help dispel any incorrect assumptions or misconceptions. The questions are not hard — the difficulty is in how long you are given to complete them.


Assessment Centre

My assessment centre day was as follows:

  • Arrived at IBM South Bank offices, take a guest ID badge from receptionist and sit in waiting area.
  • Greet others and get to know them as they arrive and sit down.
  • Met by two very friendly current Industrial Trainees (ITs) and taken to a meeting room.
  • Take a timetable and a few forms in the meeting room and fill them out, as well as some drinks and biscuits.
  • Sit through a couple of introductory talks from friendly recruitment people, the current ITs and some ‘foundation’ people (who take care of the well-being of IBM employees).
  • Attend a ‘personal interview’ with a foundation person. This took something like half an hour and consisted of mainly background questions. The interviewer was very friendly, funny and did not make me feel pressured.
  • Do a ‘team task’ within half an hour, involving sitting in front of a few recruitment people with other applicants and solving a task as a group. This is mostly to see what your teamwork skills are like.
  • We would have had a ‘business interview’, which would be a more job-specific interview, but this didn’t happen at our particular assessment centre (the interviewers were not available that day).
  • Do a second, different team task. This also involves solving a task as a group. Again, a few recruitment people sit silently and watch but do not answer questions.
  • Lots of breaks in between for drinks and biscuits, as well as chatting with the current ITs.

This is it. It’s a very relaxing day (even with the interviews and tasks), and an enjoyable one too. I felt well prepared for the interviews and so had nothing to worry about.



This is an odd stage. Essentially, IBM like you as a person and want to offer you a job but as it is such a large company, they cannot have managers from all projects and departments interview you. Instead, they send your CV around to a set of managers and let you know if any of them are interested in you. This usually involves a phone call (often in the evenings, too) from a manager who wants to know a few things more about you to see if you’re right for their project.

In this stage, you are likely to get a job but not guaranteed. Unfortunately, this is a bit of a waiting game and you just have to be patient. Once somebody likes you, they might call you with some questions, ask you to come in for an interview or offer you the job without either (for me, it was the latter).


During the Placement

IBM do not provide accommodation during your placement, so you have to rent private accommodation nearby with your salary.

If you join the Facebook group for the Industrial Placement for your year, you can find others who are in your shoes willing to share a house with you. This works out fairly cheaply.

Your expenses are likely to include the following:

  • Rent to a private landlord
  • Half of your student tuition fees
  • Electricity/gas/water
  • Income tax/national insurance
  • Travel expenses
  • Food/clothing/socialising etc.


  • You get a work laptop to use for the year.
  • Since you are still technically a student, you do not have to pay council tax as long as you fill in a student exemption form.
  • You can still receive a partial maintenance loan from student finance bodies.
  • You can live with other placement students in a house share, just like at university.
  • IBM rewards gives you discounts for many retailers.

I hope this is helpful to people who are in the situation I was in not long ago. Please comment and let me know what you think or if you have any questions or suggestions.

When Eclipse won’t generate/locate

I’ve just come across a rather irritating habit of the ADT toolset for Eclipse and thought I’d share it.

If you get a red line under “R” in a reference to a layout, string or id, (e.g. the “R” in R.layout.main) then your problem could be one of the following:

  • You have ‘android.R’ as an import in your java class. This should not be there, remove it
  • You need to ‘clean’ your project by going to Project > Clean on the Eclipse menu bar
  • You do not have Eclipse set to ‘Build Automatically’. Do this by going to Project in the menu bar and ticking ‘Build Automatically’

My problem, however, was none of these. Eclipse just refused to generate

It turns out that if you have any errors in your xml files (strings.xml, layouts, etc.), then your file will not be generated and you will not be told this is the reason.

Make sure any errors in your xml files are fixed and your file should be generated automatically when you save.