C++ 11 tip of the day

If you’re working with code using C++11 ‘s use of the <thread> library, and you get this error at runtime:

[code lang=”bash”] terminate called after throwing an instance of ‘std::system_error’
what(): Operation not permitted
zsh: abort ./main

That means you forgot to tell g++ to link to the pthread library when you compiled. Add the flag

[code lang=”bash”] -lpthread [/code]

to your g++ command string, and you should be set to go.

I’ve run into this error a few times already, and I haven’t found a good google search that answers it, so I decided to write this one. Hope it absolves a few head-scratchers out there….

Posted in Coding, Open Source | 2 Comments

Irssi OSD notifications

I wanted irssi to ping me using Ubuntu/Gnome’s on screen notification system, but didn’t want to dig into irssi’s code… what is one to do?

Cobble scripts together of course! Here’s how I got it done:

  1. Download this irssi plugin: fnotify.pl
    This script will update a text file  (~/.irssi/fnotify) with a new line every time you are pinged
  2. Put fnotify.pl in ~/.irssi/scripts
  3. autorun this script by executing:
    ln -s ~/.irssi/scripts/fnotify.pl ~/.irssi/scripts/autorun/fnotify.pl
  4. start irssi, and run:
    /hilight -nick {your_nick}
  5. When someone pings you, check the ~/.irssi/fnotify file for that ping, it should be there
  6. Download my script below (call it lastline_notify) and run it like this:
    ./lastline_notify ~/.irssi/fnotify & disown

[code lang=”python”]
import os
import sys
import pyinotify
import pynotify

if (len(sys.argv) != 2):
print "usage: lastline_notify "
filename = sys.argv[1]

class PTmp(pyinotify.ProcessEvent):
def process_IN_MODIFY(self, event):
print "Create: %s " % os.path.join(event.path, event.name)

#get the last line in file
with open(filename) as myfile:
msg_text = (list(myfile)[-1])

msg = pynotify.Notification("Irssi Notification:", msg_text)

wm = pyinotify.WatchManager()
mask = pyinotify.IN_MODIFY
notifier = pyinotify.Notifier(wm, PTmp())
wdd = wm.add_watch(filename, mask, rec=True)

while True:
if notifier.check_events():
except KeyboardInterrupt:

Viola! You now get a message in the upper right hand corner like if someone were to ping you on empathy. There might be a better way to do this, but it works for me! Both channel pings and queries should get a notification. This script runs as a daemon, so you shouldnt have to worry about it gobbling up CPU.

Posted in Open Source, Random, Ubuntu | Leave a comment

Legos and Turing machines

Jeroen and Davy over at legoturingmachine made a pretty cool little turing machine to honor Turing‘s centennial birthday. I thought I’d repost!

Check out the video:

LEGO Turing Machine from ecalpemos on Vimeo.

Pretty cool way to honor the theoretical basis for all modern computing!

Posted in Hardware, Random | Leave a comment

Gnome notifications from your Terminal!

Its pretty easy to get your terminal to notify you using Gnome’s libnotify system and a short python script. Python’s pynotify package (available as Debian/Ubuntu package: python-notify) I use this short script occasionally to notify me when a long compile is done like this:

[code lang=”bash”] make && echo "Done compiling!" | notifier [/code]

Short python script in my $PATH called “notifier”

[code lang=”python”]
import pynotify
import sys

pynotify.init("Quick Notify")
input = sys.stdin.readline()
msg = pynotify.Notification("Shell Notification:", input)

Posted in Random, Ubuntu | 3 Comments

Android ARM inline assembly

If you happen to want to write some inline assembly in Android, its just about as easy as you’d expect! See the code snippet below for a simple example of how to add two numbers in assembly on ARM.

Download code with Android makefile

[code lang=”c”]
include "stdio.h"

static inline int add(int a, int b) {
int sum;
__asm__ __volatile ("add %[c][/c], %[a], %[b]"
: [c][/c] "=r" (sum) /* one output */
: [a] "r" (a), [b] "r" (b) /* two inputs */
: /*code does not clobber*/ );
return sum;

int main(int argc, char ** argv) {
printf("sum is %in", add(4,222));
return 0;
If you run this on your android device (say, a pandaboard), you’ll see:
[code lang=”bash”]sum is 226[/code]

Now, this is just a simple example, I’m sure you will want to do something more complex. You should read up and make sure you know what you’re doing before you start tinkering with assembly, or you might be left with head scratching and your code broken… Some recommended reading

Happy hacking!

Posted in Coding, Hardware, Random | Leave a comment

The Cupholder Problem

There’s a little story I always think about when designing or modifying an established, well entrenched API, and it goes like this:

Back a few decades ago, no cars had cupholders. A team of engineers were given the task to add a few cupholders to the new car model, so they went down to their local convenience store (like 7-11) and bought all the varieties of cups that the store had. They then analyzed the cups and designed a cupholder for the car that would work with all the different sizes of cups, and put it in their new car.

Fast forward a few decades, and all the cars had cupholders. The convenience store had to design a few new cups to accommodate new demands, so they went to their office parking lot and measured all the car’s cupholders. The analyzed the car cupholder data, and came up with a cup that fit most the cars in the parking lot.


Now, I have no idea whether this story is true or not. I would guess that it’s not true if I were a betting man, but its somewhat reasonable that it could have happened. I’ve seen things like this happen first hand, where you have two moving targets designing for each other. But it does illustrate a problem that often happens when two distinct teams are designing around each other.

The core of the problem is that the two teams are designing around each other, and not coming to an agreement on what to get done. Toyota shoots to meet the changing requirements of 7/11 and 7/11 shoots meet the changing requirements of Toyota, and the result is that both teams miss the mark slightly.

In this situation, 7/11 and Toyota probably don’t have a very strong relationship, so thats expected. Even within one company though, this happens between teams if you don’t come to clearly defined specifications. Team A designs an api to finish processing some task in 10 ms for Team B. While Team A is working on that api, Team B accepts a new task to add more functionality, and they now need the task to be done in 5ms! The options are that 1) Team A has to unfairly work extra hard to cover the changing requirements or else 2) Team B will look foolish. Neither of these are good, 2) has immediate consequences and 1) will lead to Team A burnout eventually.

I don’t have any grand sweeping conclusions about this I can sum up in one sentence. Most people have probably stopped reading by this paragraph even. 🙂 I’m sure that if you’ve worked in engineering teams before, you’ll have had experience in situations like this, and your experience will be a stronger anecdote than anything I can say about my little story. Just think when you’re working, am I designing for the specification, or am I specifying the design?



Posted in Uncategorized | Leave a comment

Installing the blob on your Pandaboard for Android

The Pandaboard by Texas Instruments is a pretty good, mostly open source little development board with one teensy problem….

the blobbbbbbbbb (illustrated by Hermes Conrad to the left…)

If you’ve followed this blog post from last week, you have an image that was built from source, and is identical to the images that linaro produces. However, you still have to go and install the binary drivers provided by TI to get things like graphics acceleration working.

I’ve been using a script by vishalbhoj from linaro here. Pretty much, if you read it, it just has a download location, and then conveinently installs the download to the proper partition on the device. I haven’t had any problem with it. The current download for the binary blob that I’m using is here, hosted by google.


Happy hacking! Let’s hope TI gets with the picture and open sources their drivers. Intel has been doing it for a long time on the desktop, and it doesn’t seem to hurt them!

Posted in Coding, Hardware, Open Source | Leave a comment

Back from UDS-Q

Me at UDS

I’m back from from the Ubuntu Developer’s Summit for Quantal Quetzal (12.10)! This was my first UDS, and it was really cool to see so many developers from everywhere come together to make the next version of Ubuntu something amazing. I saw a lot of cool presentations, sessions, and talks. I also got a bit of sightseeing in in Oakland, San Francisco, and Berkeley on the weekend and at night.

Although I mostly went for planning the next version of the Ubuntu desktop interface, there were a lot of cool things going on with cloud computing as well. I learned a fair amount about MAAS (rapidly deploying thousands of servers) as well as other cloud services like Juju. We saw Mark and the founder of an ARM server company debut a new high density servercluster that runs Ubuntu, and were given some details about just how pervasive Ubuntu is in the cloud computing market. Open source remains ahead of the curve on the server!

The next desktop for Quantal Quetzal is shaping up well too. The best summary was during the Desktop roundtable on friday, where all the topics related to the desktop were discussed and summarized. You can see the notes from this session here. Hopefully will continue to improve how beautiful Ubuntu is, and make the desktop experience even more cutting edge and smooth.

Ubuntu on ARM Showing the Schedule

Welcome Canonical

        Another cool thing I was able to see and learn more about was Ubuntu running on ARM devices. This project is ran by the Linaro Foundation, which is a nonprofit dedicated to bringing open source platforms (Android and Ubuntu) to ARM devices. They’re doing great work, and I even have a PandaBoard to experiment with! The powered all the HD televisions (probably about 20 setups) in the hotel, which displayed the UDS schedule. There’s a picture down below. Its awesome that Ubuntu is running so well on ARM!

From seeing all the bright people working on open source at UDS, it looks like Quantal Quetzal is shaping up to be a great release!

Only in Oakland!

Ubuntu in the Lobby

Posted in Open Source, Ubuntu | 1 Comment

Building Linaro Android (12.04 or daily) for Pandaboard

I recently came into possession of a TI pandaboard for ARM development. Its a pretty cool little package, but if you want to build from source, you run into all sorts of old outdated wiki’s from Linaro that have you chasing your tail trying to build the android tree from source. Here’s how you do it as of May 2012

You have to get a ARM cross-compile toolchain and an android source tree that are in sync with each other. This is the tricky part, because its not exactly well tagged on the internet which version of the toolchain will work with what version of the source tree! When I was trying to match the versions myself, I kept running into all sorts of compile errors because the toolchain tools and the makefiles weren’t based around the same version of the toolchain.

After asking around on IRC, I figured out that linaro makes a build script for each daily/release version that has the URL’s for the proper versions of the source tree and the toolchain. This script is called linaro_android_build_cmds.sh. You can find these scripts on https://android-build.linaro.org/ Just find the build you want to replicate, and find linaro_android_build_cmds.sh in the download section, and download the script. For instance, you can find this script for the 12.04 release is here under the downloads section.

If you want, you can just chmod +x the script and run it. It should download the right files and build on your system. However, if you’re like me and would rather take care of these steps manually, the prebuilt toolchain URL is in avariable in $TOOLCHAIN_URL, and the repo commands and URL to init the android tree are plainly available in the file.

Happy ARM hacking!

Posted in Coding, Hardware, Open Source | 1 Comment

Let the Go hacks begin….

I’ve been tinkering around a bit more and more with Google’s Go language, and I’m finding that I like it more and more.

I think its a great good evolution of compiled languages. A few quick thoughts on what I like so far:

Novel way to handle concurrency

With C or C++, you have to write a pretty big chunk of code to spawn a new thread. With Go, you just have to write
go function(), and its as easy as that!

Furthermore, in C/C++ you’re constantly dealing with locks to ensure data is protected. As you know, this can get pretty hairy. In go, you can set up a system based on locks as well, but you can also use Go “channels”. Talking about Go channels really deserves its own series of articles, but pretty much, a channel is a way that you can instruct independent processes to wait for data to become available, or to signal that data is available. This lets you ensure concurrency without ever having to think in terms of locks and unlocks. Furthermore, you can send arbitrary data types on these channels, allowing you to process data in one thread, and then send the finished result to a waiting thread very easily. Its a novel shake-up to the way concurrency has been thought of in a lot of other languages that I’ve seen.

Garbage Collection

Garbage collection is a nice feature to have in a language. You can make a strong academic case for manual garbage collection, but at the end of the day, its easier to allocate and forget it. I’ve heard that Go’s garbage collector still needs some work (as all collectors do), but I’m sure as the language evolves it will have less and less overhead…

Compiled language

I mostly live in the OS level, and interpreted languages just don’t do in a lot of situations I come across. Having a language that is directly compiled to the architecture’s assembly, and directly executable without any runtimes is something that is great.

Moderately easy C bindings

Go’s authors provide a moderately simple interface to use C code. As with a lot of bindings, its a bit funny at times, but I’ve been using it to great effect to add C functionality to go code.

A Functional Language that’s learned from Object Orientation

You can go back and forth over whether its better to use a functional language or an object orientated language, but I think it just comes down to what you need to use it for. It is indeed nice to be able to tie a set of data to a set of useful functions on them, but at the same time, but at the same time, I find its easy to get bogged down in semantics and formalities of very strict object oriented languages.

Go is a functional language, but it works around with this with some very simple ideas:
1) There are no classes, but there are packages that group similar code together. You don’t have to deal with header files and book-keeping either.
2) In a struct, a data member is accessible globally if its a capitalized, its accessible only within its package if its lowercase. So for instance, foo.bar would be only visible within its package (aka, private), but foo.Bar would be accessible from any code that imports the package (aka, public). Its a simple idea, and I have to say it works great.
3) A struct type may be associated with a function. This lets you designate a function, say Sort, and then tie it to struct. Anyone using the struct can say Foo.Sort(), and the Sort function will get all the data in Foo as a parameter of the function. This too is simple, and works really well.

Real native interface types

Its a compiled functional language, but it gives you access to slices, a powerful way to manage arrays that has native support for a lot of the things C++’s vector library can do (without a lot of the strangeness of that library…)

Really, whether you love functional or object oriented, you should give Go a try!

Posted in Uncategorized | Leave a comment