Archive for programming

If you’re going to write an init script, do it properly

“How do I make my Linux process auto-start?” is a fairly common question.  The answer is fairly simple, thank goodness.  Write a shell script, put it in /etc/init.d and run <code>update-rc.d myScriptName defaults</code>.  And you’re done.

Except you’re not, probably.  If you haven’t written your script correctly, you might well hang the boot process.

Init.d and all those rc.d folders are part of the Unix System V init process.  Unlike modern replacement Upstart, init starts processes in series, never in parallel.  If your startup script doesn’t exit, then init won’t either.  If you’re written a really lazy script that doesn’t detatch after starting a process, then you’re screwed 🙂

Another thing to watch our for is how your script is called.  Init will pass either “start” or “stop” to the script depending on what the process should be doing.  If you don’t handle the difference between these (in a case statement, say) and instead just execute the same code whenever the script is run, you’re going to have a really fun time when you try to shutdown or restart your server.  Especially if your script doesn’t detatch and hangs init.  Because then you’re not going to be able to shut down your server cleanly.

It’s been a fun week for my test VMs!

Here’s a little bonus for you.  If you want to start several processes in a specific sequence, you can do this by writing your startup scripts so they don’t exit until each process is ready.  Init allows you to determine the order in which you start processes within a runlevel (that’s what the numbers in the symlink filenames mean) and you know from the above that you can prevent init from processing the next script in it’s queue.  Use this knowledge wisely.


Eclipse debugger tips – the “Display” view

Window -> Show View -> Display.

Type some code into this view, highlight it and then press the “J” button in the top right of the frame.  This will execute the code and return the results.

I’ve been using Eclipse for over three years and I only found about this feature the other day.  Oh well, we live and learn.

Comments (2)


“We’re always talking about wanting to make a webcomic – why don’t we actually make one?”

“Yeah, alright…”


So I’m now making a webcomic with my sister. I’m not going to link to it from here, since this is meant to be my more professional blog, but I want to briefly talk about it. I just spent a few hours hacking together a website for the comic using PHP, along with an upload page and a mini-blog for each individual comic. I’ve learnt how to do a few new things in PHP that I’ve never needed to do before, so I’d say that it was a productive evening.

Comments (2)

Where have you been, Brian?

It’s been far too long since I last wrote anything here. Let me give you a quick summary of what I’ve been up for the last few months…

Read the rest of this entry »



My NerdKit arrived last week. I haven’t had as much time to play with it as I’d have liked, but it’s still awesome. I’ve built the first two examples, a temperature sensor and a binary adder. I’ve modded the adder to light up a couple of LEDs depending on the sum, which taught me how to set pins as output and drive them high or low. It’s all done with bitshifting and logical operators. The variables that control things like input or output are stored in 16 bit integers (if I recall correctly). Each bit stores a boolean value referring to a single pin or setting. With some nice logical operations, it’s possible to retrieve a single bit, or change a single bit to a 1 or a 0. I might write a guide about this someday.


So, what should I tackle next? Should I upgrade the binary adder into the binary RPN calculator that I talked about before (this would require buying some more switches) or should I try to drive the piezoelectric buzzer at frequencies corresponding to musical notes and make music? How can I choose?!

Comments (9)

I ordered a Nerdkit

This morning I finally got around to ordering the Nerdkit that I’d been drooling over for the last few weeks. After I’ve built all of the example projects, I plan to order some more switches (and probably some more LEDs) from Maplin and build a binary RPN calculator. Because, you know, that’d be way cool.

More on the Nerdkit when it arrives!

Comments (2)

Hitori ja nai!

I’m working on a Hitori solver. I’ve nearly finished encoding the rules. I’ll then see about writing some kind of algorithm to solve the puzzle.

Tonight’s task was to write a graph structure to represent the game grid. One of the rules is that the un-blackened-out squares must form a connected graph. It was fairly easy. I’m using depth-first search from the first non-black node to determine whether the graph is connected or not. Recursion is nice 🙂


Nogizaka Haruka no Himitsu – first impressions (plus some programming talk)

I just finished watching the first episode of Nogizaka Haruka no Himitsu (Haruka Nogizaka’s Secret) and I was moved enough to blog about it.

The show is a new Japanese anime that started airing a few days ago. I originally decided to watch it simply because of one my favourite voice actresses, Noto Mamiko is playing the main character. I then promptly forgot why I wanted to download it. While watching it, I had absolutely no idea what to expect from Haruka. When she started to speak, her voice hit me like a crossbow bolt through the heart. Bam! Instant win!

There is more to the show than just Noto Mamiko, of course. It’s a story about the most popular girl in school being a closet hardcore anime fan (or otaku). She gets found out in the very first episode by the male lead, which starts them down the path of romance. Exactly the kind of show I like to watch.

Moving on from anime, I’ve been working on some programming `stuff’ lately. I’ve been teaching myself PHP, for starters. The problem I always have with learning new things is deciding what to do with them. Sure, I could make a nice PHP powered website, but what should it do? Perhaps I should start writing down all of the ideas that I come up with, to help me through uninspired times…

Anyway, I made a nice PHP image viewer. It lets you browse through a directory hierarchy and view all the images in a directory one at a time, with previous and next buttons. There are a bunch of other options on it as well, but they’re not particularly interesting to write about. Once I’ve finished it off (there are just a couple of features left that I haven’t implemented) I’ll upload it to my code section with a full write-up.

I’ve also started learning C# properly. I learnt some bits of it during my third year Computer Games Technology course, but then just left it. I didn’t learn it very well, either, since we were mostly focusing on XNA. So, I bought myself a copy of C# Precisely and started reading. I didn’t get very far, as I discovered that I didn’t have the SDK installed, so I couldn’t even get the first example program working.

I’m going down to Surrey tomorrow for my graduation ceremony, which is on Wednesday, so I won’t be doing anymore programming until Thursday. Then I’ll attempt to dive into some C#! (Spoiler for the future: Brian attempts to carry on learning C# but is constantly hampered by his family asking him to make little changes to websites, fix their Microsoft Word documents, go up to Tescos to help with the shopping and play Tibia with them. He spends the day looking forward to when they leave him alone for nearly two weeks at the end of the month.)

Oh, and a little side note, I’m taking the first two Shakugan no Shana novels with me down to Feltham/Egham. If I feel like it, I might write a little review of them when I get back 🙂


Website finally live!

After quite a lot of tweaking, I’ve finally uploaded my styled website to my main domain. The site now uses PHP, CSS and HTML 4.01 Strict. The whole thing validates, and I’ve put those little W3C validator buttons on there as proof. Also, they make it a lot easier for me to check whether a page validates or not!


I’ve also released a new program! If you check in the ‘Code’ section, you’ll find a C++ wordcount program for Windows. Having used Linux for three years at university, I got used to certain features that I wasn’t happy to live without. Wordcount is one of those! It was good C++ practice, and it taught me qute a few useful things.


In other news, I created a web questionnaire for the <a href=””>Fen Line Users Association</a>, whose website I maintain. The questionnaire hasn’t gone live yet, but it will before too much longer. It takes people’s answers, escapes any control characters then dumps them in a MySQL database. It’s not exactly a perfect use of a database, but it taught me about using PHP with MySQL, two parts of LAMP. I have no idea whether they’re using Apache on Linux, though, but it was cool all the same.

Comments (13)


It’s been about a month since my last exam. I think. Time has gone either quickly or slowly. I’m not really sure anymore. It seems a long time ago, but if I think about it – or check my diary, which I just did – then it’s been just under four weeks.


I’ve been learning some CSS recently. I did have a web technologies course in my first year, but it wasn’t very good. The normal lecturer didn’t take the course, for some reason, and the lecturer who ended up teaching the course had about two days notice to learn the material. Don’t get me wrong, I really enjoyed her lectures, but it somewhat put me off the whole ‘web’ thing 😉

Point is, I now have some basic CSS knowledge to go with my basic PHP and HTML knowledge. I have used this knowledge to upgrade my website. I’m not sure that everything is working yet, so I’ve put it up on a subdomain – Once I’m awake enough to give it a proper test (that’d be after I’ve slept, I would think) I’ll finally upload it to the main domain.

The site is still rather lacking in content, but, darnit, it’s finally got some style!


« Previous entries Next Page » Next Page »