Category Archives: Software

The road less travelled: CPU architectures

Computer Architecture: A Quantitative Approach by John L. Hennessy & David Pattersson
Computer Architecture: A Quantitative Approach by John L. Hennessy & David Pattersson

For quite a while I’ve wanted to know more about the inner workings of CPUs in order to better understand why certain things are the way they are, endianess for instance. I posed the question on what book to get on the subject over at Stack Overflow and one of the recommendations was “Computer Architecture: A Quantative Approach” which arrived today.

The book is rather heavy and the kind of book where you’d like to have a professor condence the important parts for you but it contains the important sections that I was looking for such as pipelining and caches.


Machine Language for Beginners by Richard Mansfield
Machine Language for Beginners by Richard Mansfield

I forgot to mention that I also ordered a copy of “Machine Language for Beginners” which is an introduction to assembly programming on the 6502. This is a classic book and it’s available online for free (linked through the cover image above).

The book is bound by a steel spiral like the one you find in standard writing pads and I’m quite afraid to damage it considering the paper is somewhat aged so chances are I will leave my copy be and read the online version instead.

Merge one Git project into a completely different one

At work we have some tooling done in .NET but like all compiled languages it is highly inflexible when you need to quickly hack up a simple tool for a one time job. After hearing my coworker rave about Python I decided to slowly transition to it in order to add the missing flexibility. A couple of days ago I needed to upgrade on of the tools which was in an especially poor state so as an excercise I started doing it in Python.

Originally I thought it would take me too long to come up with something useful but one thing led to another and all of a sudden I had an application which by far surpassed the poorly implemented one. I had my Python code in a separate Git repository from our tooling repository since I didn’t really expect it to turn into something useful but now I realized that the value of the new tool really warranted it to be imported and to superceed the old one. The problem I was faced with now was how to import my Git repo into the central tooling repo without losing its history.

After spending a while googling and just getting hits on how to use git-cvs or git-svn to “import” or “merge” your existing cvs/svn repo into a shiny new Git repo I decided to go to #git for some local help. There the user Ilari pointed me to in the right direction which was to use a Git subtree merge strategy. Googling that I immediately found “How to use the subtree merge strategy” which was precisely the solution I was looking for!

So far I have not found a single use case that I needed which Git doesn’t already cover.

Third stop: The Temple, Projects and Machine

Yet another load of books arrived on Friday last week.

Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig
Zen and the Art of Motorcycle Maintenance by Robert M. Pirsig

A philosophical book on the concepts of quality. This books is very highly regarded in the software industry so I decided I better read it. It is about a motorcycle journey made by the author, his son and two friends during which he contemplates on various philosophical topics.

I’ve read through a few chapters so far and I must say that it is beautifully written and if you are like me you will probably want to get a motorcycle after reading this.

The Mythical Man-Month by Frederick P. Brooks
The Mythical Man-Month by Frederick P. Brooks

Another book seen as a must read by software developers. It covers topics on managing software projects and is organized as a series of essays based on the authors real-life experience from working at IBM on the System/360 and later OS/360 projects.

If you are in the software industry you have most likely heard about this book before.

Core Memory: A Visual Survey of Vintage Computers by John Alderman et. al.
Core Memory: A Visual Survey of Vintage Computers by John Alderman et. al.

Core Memory is a beautiful coffee table book which presents the reader with beautiful photographs of various vintage computers along with brief summaries. It covers such machines as ENIAC, the Apollo guidance computer and the all too famous Commodore 64.

So far I have only flicked through a couple of pages but the photographs are beautiful and high res. If you share my passion for vintage computers this book is a must.

Mazda 626 and Mx-6 Ford Probe Automotive Repair Manual by Jay Storer et. al.
Mazda 626 and Mx-6 Ford Probe Automotive Repair Manual by Jay Storer et. al.

It’s your run of the mill Haynes manual so it should need little introduction. I have a tugging sound somewhere in the steering system of my Mazda 626  so I decided to get the manual in order to make my life easier when fixing it.

Come join the book parade

Last week I decided to actually start buying the books on my Amazon wish list. A friend of mine tipped me to try buying used books since they are generally much cheaper and usually in very good condition. What I realized was that many of the retailers on Amazon Marketplace actually carry books that are new and they can still be half-off or cheaper compared to Amazon’s price. Thanks to this it was suddenly much more realistic that I would eventually own all of the books on my list and that inspired my spending spree.

The first two books arrived today.

How Would You Move Mount Fuji? by William Poundstone
How Would You Move Mount Fuji? by William Poundstone

How Would You Move Mount Fuji? is about the practice of asking puzzle questions during job interviews in order to select the truly creative applicants applied by large software companies such as Microsoft. I’ve seen this book recommended on several occations and it has been on my wish list for a long time.

So far I haven’t been subjected to this personally but I really like the idea of asking a tricky question in order to see how an applicant thinks. As I understand it from reading the introduction a lot of people will give up instantly given an impossible question.

Hardware Hacking Projects for Geeks by Scott Fullam
Hardware Hacking Projects for Geeks by Scott Fullam

Since I work as a software developer for embedded systems I’ve been wanting to brush up on my electronics skills in order to better understand what is going on under the hood. Recently I stumbled on a thread on Stack Overflow asking about good books for programmers who want to get into electronics and this was one of the books recommended.

So far I’ve only skimmed through the book but my first impression is that it is a lot simpler than I had hoped. The book consists of a number of projects such as “How to Hack a Furby” and “How to Build a Home Arcade Machine“. It goes through each project step by step but doesn’t really explain any of the decisions made. The book is probably more suitable to someone younger who has little to no experience with electronics.

Installing RubyGems on Solaris 9

We are using some Ruby on Rails applications at work and I’m impressed with how well they all work so I decided to install it on my private server as well. I’m using Ruby from Sunfreeware but they do not provide a packaged RubyGems. Considering it has its own package management I decided to install it manually.

I followed the installation instructions and executed “sudo ruby setup.rb –prefix=/usr/local” which proceeded to install gems into /usr/local/lib/rubygems. After the installation completed I executed gem in order to see that it had installed correctly but was greeted by:

bash-2.05$ gem
/usr/local/bin/gem:8:in `require': no such file to load -- rubygems (LoadError)
        from /usr/local/bin/gem:8

Which wasn’t quite what I had expected. After some googling I found that in order to get a list of dirs which ruby looks for libraries in you should execute “ruby -e ‘puts $:'” which produced:


As you can see /usr/local/lib is not in this list so I moved rubygems, rubygems.rb, ubygems.rb and rbconfig to /usr/local/lib/ruby/site_ruby/1.8.

After these steps I was able to run gem and I performed a successful install of rake.

Rescheduling ISC cron jobs

We have a SLES server running at work and recently we’ve had issues with the groupware server failing to respond during certain hours of the day. After some sleuthing I found out that it is caused by the backup scripts for the database server. At first glance you might think that the database is being locked during the backup process but it happens even if I’m just copying the (transaction) log files using cp so I’m blaming it on the really slow drives in that particular server.

Now I wanted to reschedule the cron jobs so at least they would run the backups during off hours but no matter how much I googled I couldn’t find any good information on how to do this. The server is running ISC cron and the crontab only points to run-crons which in turn executes the scripts in /etc/cron.{daily|weekly|monthly}. After some more manual labor I found out run-crons is just a script and as it turns out it simply touches files in /var/spool/cron/lastrun whenever it runs a job in order to keep tack of when to run it again.

I’ve never had to fake creation times of files in a Unix system so again I turned to Google and apparently the answer is really quite simple. The touch command has an option, -t, which allows you to set the timestamp of the files rather than just fetching the current system time so I just modified the time of the cron files to some nice value in the middle of the night when very few people access the groupware system and vóila, problem solved!

The idea of the thread throttling class

One particular problem in programming is when you have a thread which only serves the purpose of doing some trivial repetetive work in a timely manner. Most often these threads are implemented as:

while (isRunning) {

In a perfect world all threads wait for signals rather than implementing this kind of busy-wait polling but when you need something simple like above I believe something as simple as busy-wait could be considered good enough in most cases.

The purpose of the sleep in the case stated above is to ensure that if doSimpleJob() completes in very few ticks we won’t end up unintentionally starving other threads while doing our trivial low priority task.

The downside to this is that if it is difficult to determine how long doSimpleJob() takes to complete, i.e. if it’s waiting for I/O, it will also be difficult to set a good timeout for sleep. If it takes five seconds to complete the job there is hardly no need to sleep for another second, and maybe you even want to run it again as fast as you can if it took a long time to complete. The solution I’m proposing is to implement a type that can determine how long we should sleep, if at all. Some pseudocode:

class Throttle {
    Throttle(Milliseconds timeout) :
        m_timeout(timeout) { }

    void sleep() {
        Milliseconds duration(Time::now() - m_start);
        if (duration < m_timeout) {
            sleep(m_timeout - duration);

    Time m_start;
    Milliseconds m_timeout;

Using this implementation the example mentioned above would become:

while (isRunning) {
    Throttle throttle(Seconds(1));

Now if doSimpleJob() takes less than a second one loop iteration would not take up more than one second and if it takes more than a second it will be instantly restarted.

One danger to this is that if doSimpleJob() is computation bound rather than I/O bound it might end up starving threads if it takes more time than the throttle timeout so it has to be applied with care.

For the sake of the argument lets assume that the implementation of sleep() being used actually sleeps for the whole duration of the specified time, no more no less.