Category Archives: code

Getting root access to a Raspberry Pi using the Netbeans IDE

I was recently able to assist a friend in enabling root access to his Raspberry Pi – in the event that this advice may help others as well, here it is:

My friend needed root access to work with the low level IO on the Raspberry Pi. While the username account supplied with a Raspberry Pi does have sudo rights on the Pi’s Linux OS, the Netbeans IDE he was using wasn’t able to use sudo when communicating with the Pi, complicating development. I advised him to set a known password to the Pi’s root user account and then set Netbeans to use the root account:

>> sudo su

This will now change to operating as the root user.

>> passwd

Set the password to something suitable – this will change the root user’s password. Now set Netbeans to communicate with the Pi using the username “root” and the password you chose and you’ll have full root access.

While I realise that logging into your PC as root is generally not a great idea, the situation is rather different for something like a Raspberry Pi or similar, which is already dedicated to a specific task.

Leave a Comment

Filed under code

pycrypto Windows binaries

Another entry in my gripping series of posts intended to remind me about various software and development things when I inevitably forget them, this time to do with pycrypto. Installing pycrypto via a regular pip install is a pain for me on Windows, as it requires some C compiling, and I don’t always have a C compiler installed or configured for pip to see. Some googling has yielded a repository of pre-built Windows links, so this is where you found them, future-me:

Leave a Comment

Filed under code, computing, python

Installing MySQL-python on a Windows virtualenv

This one is more for my own reference when I inevitably forget how to do this: I needed to install the mysql-python connector into a virtualenv on my Windows system but could not get it to do a pip or easy_install install for a variety of errors: a missing header file and a missing compiler batch file amongst others. I solved it by using a pre-compiled package from this excellent list of pre-compiled Python Windows packages and then instructing easy_install to install it (which I didn’t realise was possible):



Leave a Comment

Filed under code, python

Reflections on why I still enjoy being paid to code

I saw a tweet from a friend today, also a professional developer, expressing dissatisfaction with writing code for a living after 7 years at it, although he still enjoys doing it as a hobby. This is not the first time I’ve seen this sentiment expressed, which is why I consider myself very blessed to still enjoy my career after 7.5+ years of being paid to engineer and develop software. After giving it a bit of thought, I strongly suspect my enjoyment has come from variety – in those 7.5 years I have:

  • Developed extensively in C, Delphi and Python, developed significantly in Labview and dabbled in C#
  • Designed and developed code for embedded devices, desktop systems and workstations in factory environments
  • Developed low-level drivers, front-end GUI-based systems and several layers in between
  • Ported large legacy systems to new platforms and architected completely new systems
  • Designed a communications spec for device-to-PC communications and designed a variety of systems and tools around it
  • Designed and implemented a variety of database schemas
  • Assisted in administering a version control system
  • Played toolsmith, developing a number of internally used tools

On top of that, I’m regularly consulted on various languages, including C and Python, and have presented training courses on both. This last point is not meant as a boast (I’m hardly a guru on either language) but an indication that I’ve been fortunate enough to get enough exposure to both languages to teach them.

Looking at the list above, I seem to have lucked into the kind of job that changes regularly and keeps me interested – I’ve come to realise how rare this is and I’m certainly not going to take it for granted.

Leave a Comment

Filed under code, work

C code that could get you fired

Here’s another stupid C trick I’ve carried around in my brain for a while:

#define sizeof(x) (rand() % 20 + 1)

The mod and addition are to give a random number in the range from 1 to 21.

This can be demonstrated with a small program:

#include <stdlib.h> 
#include <stdio.h>

#define sizeof(x) (rand() % 20) + 1

void main()
  int i;
  printf("Sizeof i: %d\n", sizeof(i));
  printf("Sizeof i: %d\n", sizeof(i));
  printf("Sizeof i: %d\n", sizeof(i));

When run, you get:

# ./random_sizeof
Sizeof i: 4
Sizeof i: 7
Sizeof i: 18

Your compiler might warn you about this, although mine didn’t (using GCC 4.3.2 with no flags) – but on a large project, there are probably so many warnings that an extra one wouldn’t be noticed anyhow (if all the large projects you’ve worked on had no warnings at all, you’re luckier than most of us).

Unlike the trick I posted previously, using this in your code will not have your colleagues worry about your competence so much as it will prompt them to fill a box with your things and show you the door…

Leave a Comment

Filed under code

C code you should never use in production

I’ve been meaning to write this little trick down for a while, so while I remember to, here’s a stupid little C trick which amuses me.

Consider a C array:

char array[3] = {1,2,3};

To access element 3, you would use


This is just shorthand for a pointer dereference

*(array + 2)

This is just addition, which is associative, so it’s the exact equivalent of

*(2 + array)

which gives you


which is perfectly valid C.


To prove that, consider this simple program

void main()


char array[3] = {1,2,3};

printf("array[2]: %d. 2[array]: %d\n", array[2], 2[array]);

After compilation

array[2]: 3. 2[array]: 3


I would strongly caution against ever using this in production. Your colleagues will worry about you if they see it during a code review or when working on code you wrote. If you don’t think they would flag it, you should be worrying about them 🙂


Filed under code

Code update

Visit the Yahoo Comics Page today and observe the wondrousness of its new and marvellous features! Tingle with joy at its remarkable amazingness! Salivate with excitement at its astounding magnificence!

In other words, I finally added the feature to my comics aggregator that I talked about with quite a while ago – the storage of the last weeks worth of comics. The comics are moved to the day’s page at 22:00 US time (I dunno which timezone, actually), so you have until the early SA morning to check out the comic from 7 days ago before it is overwritten forever by today’s.

If this makes no sense at all, kindly ignore – I know what I’m talking about, honest…


Filed under code, Uncategorized