Archive for the ‘Geeky’ Category

You are currently browsing the archives for the Geeky category.


Seven Things

I got … seven-thinged.

I’m not sure If you can call it like this, but no other name came to my mind right now. But I got seven things tagged by the Upstream Guys / Girls. The rule for this little game are pretty straight forward:

  • Link your original tagger(s), and list these rules on your blog.
  • Share seven facts about yourself in the post — some random, some weird.
  • Tag seven people at the end of your post by leaving their names and the links to their blogs.
  • Let them know they’ve been tagged by leaving a comment on their blogs and/or Twitter.

So during the next seven bullet points you will get to know things you never thought about before about me … or so!
Let’s go:

  • My blog is called “Martin en Neukoelln”, but I dont live in Neukoelln anymore, I’m just too lazy to change the title!
  • I love kicking peoples asses on the phone when I’m complaining about something!
  • My research topic is main memory databases, but I would really need a database to remember anything – what did I just say?
  • Right now, I really hate the frickin Safari ‘I-always-forget-about-cookies’ Bug!
  • Sometimes I am jealous of all those people working at startups or being a freelancer!
  • During high school, I was selected as the teachers most annoying pupil!
  • I do love hacking and programming languages!

To carry on the chain I would love to tag – Andre, Matthieu, Christian, Katharina, Palo Alto, Martin and I ran out of names and people that still write blogs (instead of only using Twitter).

Debugging in the terminal! or A short introduction into GDB

Almost everybody of us already wrote at least a small C or C++ program and struggled with different problems along the way of completion of the program.

Since C or C++ is mostly written in plain text editors fancy features like typically available from Java (debugging, IDE support etc) are not available. Of course one can argue there is Eclipse CDT or NetBeans or even Windows, but all these programs have a huge drawback when it comes to custom maintained makefiles etc. But back to the topic. What happens if we see that errors occur during program execution. Typically the easiest solution is to write simple debug output statements issuing text that helps to understand what is wrong. Of course again writing tests would make everything easier, but again I must contradict (at least in the beginning) – writing tests in C or C++ is pain in the … and for exploring features or the languages it’s simply not useful.

The more complex the program structure get, the more complex it becomes to create useful debug statements that help to understand what is going on and very easily you come to a point where you say:

Damn, I missed to add this and this statement here and there and now I have to compile everything again…

This should not be. Even for people that are typically used of graphical development environments it is not to hard to understand how GDB works and how to became in a short time capable of mastering the most important tasks.

The big question is: Where to start? Let’s assume we have a program that crashes and now we want to debug it. I prepared a very easy program that crashes soon after starting the program.

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

void test(int a)
{
	int b = 10;

	float c = b + 100;

	printf("%f", c);
}

int main(int argc, char** argv)
{
	int a = 10;
	float f = 10.2;

	test(10);

	int *e = NULL;

	int b = *(e + 10);

	return 0;
}

This program as is will fail because of a simple reason: there is an assignment of a variable with not assigned value to another variable. The question is now how to start debugging if the program once compile (don’t forget the -g flag) and dumped with a segmentation fault etc.

The first step is to start GDB using the simple gdb command from your favorite terminal. Once it is open it will look like the following:

GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".
(gdb)

This screen tells you that GDB is ready and waiting for your input. Right from here you can start build, run, debug etc using the interactive GDB console. The biggest problem I see right here is, that there is no nice screen that tells you how to start debugging and so you are left alone a little bit. To overcome these initial problems I will explain you the most important commands for GDB and show you how to use them later on in a small screen cast.

So here is the list, sorted from most important to least important:

  • file – specifies which executable to load. Once specified this will be used through the rest of the session.
  • run arg1…argn – this will run the given program and break if it reaches a breakpoint or an abnormal program state
  • break < em >location – set a breakpoint at the given location. This can be a symbol, a filename or an address.
  • print symbol – prints the value of the symbol. Can be used as a plain debug output statement
  • step | next | continue – they do what they look like. Step steps into the next available source position, while next proceeds to the next position in the same function and continue continues until the next program stop via a breakpoint, exception or program termination.
  • bt – prints a backtrace for the current position. This can be used to examine the current position in the stack
  • frame number – used to navigate to the given frame and show frame info.
  • list {+ | – | location} – display the corresponding source code for the given position or location. + and – navigate up and down the source file.
  • info scope function name – displays all local variables of the given scope. This can be use to check which variables are defined.
  • whatis symbol – prints the type of the symbol

Using these commands you have a suitable knowledge about how to work with GDB. Now using a screencast I will show you how to use these shortcuts in action.


GDB Introduction from Martin on Vimeo.

Colored output for gcc and friends

Tired of using search to find the errors in your GCC output?

Hunting down errors in C and C++ is hard enough and so is hunting down the error message in the compiler output. A few years ago (actually more than ten) Jamie Moyer sat down and wrote a nice Perl script that parses the output so that it creates colored output on a colored terminal.

Unfortunately the only location where to get this script right now is from Johannes Schlüter’s website.

Terminal with colored gcc output

And what should I say more – this looks very pretty. By the way the nice Terminal theme came from InfiniteRed – readable black theme, nice.

DBLP Bibtex

This is for all you out there writing masters thesis, bachelor thesis, phd thesis or just your next book and you are using Bibtex for managing your bibliography. But like me you now the pain of maintaining the Bibtex file: Find the source you want to cite, than find the correct bibtex entry and than add this to your bibtex file.

Argh, thats not DRY style, hein?

Ok, pals, I have the solution for you: You know DBLP, the cool guys that enter all the conference proceedings in there system, so that you can browse for conference papers and find the correct bibtex. But everything you need to do now is to know the cite key and thats all. The rest is done by the hilarious dblp gem.

sudo gem install dblp

Use Case? You are looking for a paper of let’s say Dean Jacobs you enter this as a search criteria in DBLP and are redirected to the following page http://dblp.uni-trier.de/db/indices/a-tree/j/Jacobs:Dean.html. You click on the small 29 in the front of the first line to get to the bibtex source. But instead of copying the whole bibtex, just take the cite key and go on with your latex documnet like the following

This is a greate paper \cite{DBLP:conf/btw/JacobsA07}

Now as ususal start the build process with running latex and bibtex. Wow, no, not bibtex. You run

latex mydoc.tex
dblp mydoc

now. That’s way easier. What it does? It downloads the required bibtex entries for you and stores them in the file “dblp.bib”.

That is really great!!!

Thanks, I know ;)

For more options just hit dblp on the command line.

Newgem for all – Newgem für alle

Es ist Zeit. Es ist Zeit mal wieder etwas auf Deutsch zu schreiben und nicht nur alle Computerrelevanten Themen auf Englisch zu publizieren.

Durch mein slimtimercli Projekt bin ich auf newgem gestoßen, ein gem, dass es erlaubt gems zu erstellen und zu publizieren. Ganz schön Meta oder? Und wen sollte es da auch wundern, dass das newgem gem von niemandem anderes als Dr. “call me meta” Nic ist. Doch zurück zum Thema. Während ich an slimtimercli gearbeitet habe, dachte ich mir, es müsste doch mal jemand ein Screencast zu dem Thema machen, gratis und in guter Qualität. Aber wer schon einmal einen Screencast produziert hat, weiß, dass das nicht trivial ist. Zuerst muss das Material gut sein, dann muss der Videoprovider auch noch eine gute Qualität unterstützen und so weiter.

Doch nach einigen Mühen ist es mir gelungen den Screencast fertigzustellen und auch hochzuladen. Wer noch nicht mit Viemo gearbeitet hat dem sei gesagt, dass wenn man den gesamten Screencast in HD schauen kann wenn man dass Video direkt auf deren Seite schaut und dann im Vollbildmodus schaut.

Und nun viel Spass mit dem Screencast.



newgem Screencast from Martin on Vimeo.

Achtung, wer das Video in voller Qualität sehen möchte, muss direkt auf die Homepage von Vimeo gehen, da eingebettete Videos leider nicht in HD Qualität angezeigt werden.

Links

[1] http://newgem.rubyforge.org/
[2] http://codeforpeople.rubyforge.org/rubyforge/
[3] http://seattlerb.rubyforge.org/hoe/
[4] http://www.flickr.com/photos/wigermo/2256994868/sizes/o/
[5] http://www.jamendo.com/en/album/5682
[6] http://rubyforge.org/projects/rug-b

slimtimercli version 0.1.3 released

Today I released version 0.1.3 of slimtimercli, the small nice and sexy command line interface to your slimtimer account. This release fixes several problems when starting and stopping tasks. Furthermore I introduced a new way of passing options to the script. For convenience reasons the old way still stays available for a few releases.

To see how it works out, check the following code


slimtimer -h

If you want to supply patches, complaints or compliments please submit them to the brand new Google Group for slimtimercli.

Slimtimer Command Line API

I don’t know how many of you are working as freelancers or do need any kind of time recording to prove their working hours or only to record how many hours they spend on their master thesis :) . For me slimtimer does very well and I am really happy with this tool. It comes directly with a small browser bookmark bar script, that opens some kind of timer and shows the current worked time on a specific task.

I think, this is fine as long as you spend most of your time in a browser, but as soon as you dig deeper on a terminal or in textmate this behavior is not really suitable – as executing a rake task you want to start and stop recording time, don’t you?

Ok, it took me a day but I created some small little command line interface for slimtimer and it works well – the only thing you need is a slimtimer account and an API key that you get without any questions directly from the slimtimer website.

The next step is installing the slimtimer command line interface on your local workstation with executing:

sudo gem install slimtimercli

As soon as the gem is installed, you need to setup slimtimercli for the first usage using the setup command

slimtimer setup

This will ask for your e-mail as username and your password and API key for authentication. Now you need to fetch your tasks and check on which you are going to start working

slimtimer tasks

Ok, now the hairy moment starts, prepare your engines, clean your keyboard and be ready to work with

slimtimer start my_shiny_task

Hours later, totally exhausted, you might stop working and of course stop the timer, how? Easy as opening a bottle of water

slimtimer end

That’s cool hey? So that’s pretty much it, more documentation can be found using

slimtimer help

Bugs, features, money or anything else can be reported here :)