<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/wordpress-mu-1.0" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Steady as a rock</title>
	<link>http://blogs.ubuntu-nl.org/dennis</link>
	<description>...or so they say</description>
	<pubDate>Fri, 25 Apr 2008 19:11:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=wordpress-mu-1.0</generator>
	<language>en</language>
			<item>
		<title>Ubuntu security notices and updates feeds changed location</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2008/04/25/ubuntu-security-notices-and-updates-feeds-changed-location/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2008/04/25/ubuntu-security-notices-and-updates-feeds-changed-location/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 19:05:28 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Ubuntu</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2008/04/25/ubuntu-security-notices-and-updates-feeds-changed-location/</guid>
		<description><![CDATA[Ubuntu-nl has outgrown its server. To reduce load on it, I&#8217;ve moved the USN and -changes feeds to feedburner. Here are the updated locations:

http://feeds.ubuntu-nl.org/UbuntuSecurityNotices
http://feeds.ubuntu-nl.org/DapperChanges
http://feeds.ubuntu-nl.org/EdgyChanges
http://feeds.ubuntu-nl.org/FeistyChanges
http://feeds.ubuntu-nl.org/GutsyChanges
http://feeds.ubuntu-nl.org/HardyChanges
http://feeds.ubuntu-nl.org/IntrepidChanges (still empty of course :))

]]></description>
			<content:encoded><![CDATA[<p>Ubuntu-nl has outgrown its server. To reduce load on it, I&#8217;ve moved the USN and -changes feeds to feedburner. Here are the updated locations:</p>
<ul>
<li><a href="http://feeds.ubuntu-nl.org/UbuntuSecurityNotices">http://feeds.ubuntu-nl.org/UbuntuSecurityNotices</a></li>
<li><a href="http://feeds.ubuntu-nl.org/DapperChanges">http://feeds.ubuntu-nl.org/DapperChanges</a></li>
<li><a href="http://feeds.ubuntu-nl.org/EdgyChanges">http://feeds.ubuntu-nl.org/EdgyChanges</a></li>
<li><a href="//feeds.ubuntu-nl.org/FeistyChanges">http://feeds.ubuntu-nl.org/FeistyChanges</a></li>
<li><a href="http://feeds.ubuntu-nl.org/GutsyChanges">http://feeds.ubuntu-nl.org/GutsyChanges</a></li>
<li><a href="http://feeds.ubuntu-nl.org/HardyChanges">http://feeds.ubuntu-nl.org/HardyChanges</a></li>
<li><a href="http://feeds.ubuntu-nl.org/IntrepidChanges">http://feeds.ubuntu-nl.org/IntrepidChanges</a> (still empty of course :))</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2008/04/25/ubuntu-security-notices-and-updates-feeds-changed-location/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Rickrolled!</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2008/03/23/rickrolled/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2008/03/23/rickrolled/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 17:32:59 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Uncategorized</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2008/03/23/rickrolled/</guid>
		<description><![CDATA[Argh, as part of a top 25 of &#8220;Bad but Gold&#8221; songs (think YMCA and co), TMF just aired Rick as well. RICKROLLED!

]]></description>
			<content:encoded><![CDATA[<p>Argh, as part of a top 25 of &#8220;Bad but Gold&#8221; songs (think YMCA and co), TMF just aired Rick as well. RICKROLLED!
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2008/03/23/rickrolled/feed/</wfw:commentRss>
		</item>
		<item>
		<title>User management tricks</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2008/03/22/user-management-tricks/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2008/03/22/user-management-tricks/#comments</comments>
		<pubDate>Sat, 22 Mar 2008 15:45:59 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Ubuntu</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2008/03/22/user-management-tricks/</guid>
		<description><![CDATA[Inspired by the latest launchpad news, here is a better version of launchpadduser.py. It does more sanity checking, can be used as a module and allows you to use a different name locally than on launchpad (eg sudo ./launchpadduser.py &#8211;launchpad-name kiko christian) Enjoy!
In related news: It&#8217;s now happened too often that I had to walk [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by the latest <a href="http://news.launchpad.net/general/using-launchpad-accounts-to-manage-your-local-ssh-logins-launchpadduserpy">launchpad news</a>, here is a better version of <a href="http://kaarsemaker.net/software/launchpadduser">launchpadduser.py</a>. It does more sanity checking, can be used as a module and allows you to use a different name locally than on launchpad (eg <tt>sudo ./launchpadduser.py &#8211;launchpad-name kiko christian</tt>) Enjoy!</p>
<p>In related news: It&#8217;s now happened too often that I had to walk a user through the boot with live cd/find partition/chroot/passwd hoops after they forget the password for their account. So I whipped up a shellscript that one can wget and run from a live cd. It searches for partitions with linux installs on them and allows you to the password for any account on them that has a usable password. So now these hoops are reduced to:</p>
<ul>
<li>Boot from a live cd</li>
<li>Go to applications » accessories » terminal</li>
<li>Type this: <tt>wget <a href="http://kaarsemaker.net/software/reset_passwords">http://media.kaarsemaker.net/reset_passwords</a> &amp;&amp; bash reset_passwords</tt></li>
<li>Reboot</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2008/03/22/user-management-tricks/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Chocolate!</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2008/02/03/chocolate/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2008/02/03/chocolate/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 14:23:14 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Personal</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2008/02/03/chocolate/</guid>
		<description><![CDATA[Fact one: Women who have their monthly problems need chocolate and preferably lots of it
Fact two: My girlfriend like to bake pies
Fact three: She has her monthly problems now (why else would I be blogging instead of spending time with her)
Result:

Now this is bad for you but tastes soooooo good!

]]></description>
			<content:encoded><![CDATA[<p>Fact one: Women who have their monthly problems need chocolate and preferably lots of it<br />
Fact two: My girlfriend like to bake pies<br />
Fact three: She has her monthly problems now (why else would I be blogging instead of spending time with her)</p>
<p>Result:<br />
<a href="http://media.kaarsemaker.net/taart.jpg"><img src="http://media.kaarsemaker.net/taart_klein.jpg" /></a></p>
<p>Now this is bad for you but tastes soooooo good!
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2008/02/03/chocolate/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ventriloquists</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2008/01/13/ventriloquists/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2008/01/13/ventriloquists/#comments</comments>
		<pubDate>Sun, 13 Jan 2008 18:53:51 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Uncategorized</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2008/01/13/ventriloquists/</guid>
		<description><![CDATA[When I was fixing the Ubuntu setup on the pc of a now happy Ubuntu user, he pointed me to a video on youtube called &#8220;Achmed the terrorist&#8221;. Achmet is one of Jeff Dunhams puppets and he is a dead suicide bomber who threatens to kill in an increasingly squeeky voice. He also has a [...]]]></description>
			<content:encoded><![CDATA[<p>When I was fixing the Ubuntu setup on the pc of a now happy Ubuntu user, he pointed me to a video on youtube called &#8220;Achmed the terrorist&#8221;. Achmet is one of <a href="http://www.jeffdunham.com">Jeff Dunham</a>s puppets and he is a dead suicide bomber who threatens to kill in an increasingly squeeky voice. He also has a christmas song now ;)</p>
<p>Anyway, apparently someone uploaded both his shows to youtube and sure enough I watched them. Jeff&#8217;s quite rude at times but overall pretty funny, at least much funnier than many so-called comedians out there. Motivated by this, I searched for &#8216;ventriloquist&#8217; on youtube and sadly the result was less than stellar.</p>
<p>Until I saw <a href="http://www.terryfator.com/">Terry Fator</a> that is. Last year Terry apparently was a candidate in &#8220;America&#8217;s got talent&#8221;, a show I didn&#8217;t even know existed. He is absolutely brilliant! Funny, good impersonator, excellent singer and amazing entertainer. If you&#8217;ve never seen him, you absolutely should go to youtube and search for his impersonation of Roy Orbison. While you&#8217;re at it, watch it all. BRILLIANT!
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2008/01/13/ventriloquists/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Traincoding: network-manager annoyance</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2008/01/11/traincoding-network-manager-annoyance/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2008/01/11/traincoding-network-manager-annoyance/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 16:52:08 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Ubuntu</category>

		<category>Traincoding</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2008/01/11/traincoding-network-manager-annoyance/</guid>
		<description><![CDATA[xs4all, the best ISP in the Netherlands, now offers free wifi at KPN hotspots to its members. This is excellent, since 3 stations I pass when traincoding now have wifi I can use, so I can use documentation when hacking and not look like an arse because I don&#8217;t read docs.
The latest quick hack didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>xs4all, the best ISP in the Netherlands, now offers free wifi at KPN hotspots to its members. This is excellent, since 3 stations I pass when traincoding now have wifi I can use, so I can use documentation when hacking and not look like an arse because I don&#8217;t read docs.</p>
<p>The latest quick hack didn&#8217;t work properly at the 2nd  station, so I looked up documentation, found my error and now I present: <a href="http://www.kaarsemaker.net/software/nm_unset/">nm_unset</a> - a very simple tool with which you can remove wifi networks for network manager from gconf. I simply got tired of having to use <tt>gconftool-2 &#8211;recursive-unset /system/networking/wireless/networks/$ssid</tt> all the time (and of having to explain how to do this to new users on #ubuntu). I&#8217;m really hoping that they soon provide something in n-m for this so I can toss this out again.
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2008/01/11/traincoding-network-manager-annoyance/feed/</wfw:commentRss>
		</item>
		<item>
		<title>So here it is, merry christmas</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2008/01/11/so-here-it-is-merry-christmas/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2008/01/11/so-here-it-is-merry-christmas/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 15:16:17 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Uncategorized</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2008/01/11/so-here-it-is-merry-christmas/</guid>
		<description><![CDATA[&#8230;oh wait new year
&#8230;oh crap, it&#8217;s the 11th already
Been quite busy the past weeks, so not much writing has happened. After christmas I finally picked up work on falcon again. Version 2.0.0 was finally finished and Brandon Holtsclaw was kind enough to upload it to Ubuntu, Yeah! Of course a few bugs were found (and [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230;oh wait new year</p>
<p>&#8230;oh crap, it&#8217;s the 11th already</p>
<p>Been quite busy the past weeks, so not much writing has happened. After christmas I finally picked up work on falcon again. Version 2.0.0 was finally finished and Brandon Holtsclaw was kind enough to upload it to Ubuntu, <a href="https://lists.ubuntu.com/archives/hardy-changes/2008-January/004535.html">Yeah</a>! Of course a few bugs were found (and fixed) after that, so version 2.0.4 will be uploaded shortly, which is the recommended one.</p>
<p>At work (where we need more linux sysadmins, prod if interested!) I have been working on a project I called imagine, it&#8217;s an OS &#8216;installer&#8217; that can make an image of your harddrive and install it on another machine. That&#8217;s nowhere near unique of course, but this thing runs entirely from initramfs so you can simply use network booting and don&#8217;t need other media than a server to store the compressed images. Best thing about it is that the COO allowed me to distribute the code as free sofware, so when that finally clears with legal, you&#8217;ll see more of it!.
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2008/01/11/so-here-it-is-merry-christmas/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Career defining moments</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2007/12/01/career-defining-moments/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2007/12/01/career-defining-moments/#comments</comments>
		<pubDate>Sat, 01 Dec 2007 12:22:06 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Uncategorized</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2007/12/01/career-defining-moments/</guid>
		<description><![CDATA[The past few weeks I&#8217;ve had to make some non-trivial choices regarding my future career and sadly this took up pretty much all my time. Since some people have wondered where I have been lately, I&#8217;m posting it here. Then again, most people probably won&#8217;t care so I&#8217;ll use a &#8216;click here to read more [...]]]></description>
			<content:encoded><![CDATA[<p>The past few weeks I&#8217;ve had to make some non-trivial choices regarding my future career and sadly this took up pretty much all my time. Since some people have wondered where I have been lately, I&#8217;m posting it here. Then again, most people probably won&#8217;t care so I&#8217;ll use a &#8216;click here to read more link&#8217;. So read more if you want to know what I&#8217;ve been up to or if you&#8217;re looking for a windows admin, linux admin or perl developer job in Amsterdam (there are many non-tech vacancies as well).</p>
<p> <a href="http://blogs.ubuntu-nl.org/dennis/2007/12/01/career-defining-moments/#more-234" class="more-link">(more&#8230;)</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2007/12/01/career-defining-moments/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ubuntu on toshiba satellite s2670</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2007/11/28/ubuntu-on-toshiba-satellite-s2670/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2007/11/28/ubuntu-on-toshiba-satellite-s2670/#comments</comments>
		<pubDate>Wed, 28 Nov 2007 00:31:27 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Uncategorized</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2007/11/28/ubuntu-on-toshiba-satellite-s2670/</guid>
		<description><![CDATA[X does &#8216;weird&#8217; things on this machine (trident chip), looks like a moire effect so I assume sync issues. Being an X noob, I can&#8217;t figure out how to fix this,  following hints found on the web (mostly involving modelines) didn&#8217;t work either. Is there anyone out there who reads this and can give me [...]]]></description>
			<content:encoded><![CDATA[<p>X does &#8216;weird&#8217; things on this machine (trident chip), looks like a moire effect so I assume sync issues. Being an X noob, I can&#8217;t figure out how to fix this,  following hints found on the web (mostly involving modelines) didn&#8217;t work either. Is there anyone out there who reads this and can give me a hint? Please?
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2007/11/28/ubuntu-on-toshiba-satellite-s2670/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Traincoding: Permutations in python</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2007/11/10/traincoding-permutations-in-python/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2007/11/10/traincoding-permutations-in-python/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 21:48:10 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Traincoding</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2007/11/10/traincoding-permutations-in-python/</guid>
		<description><![CDATA[To my shock, I didn&#8217;t find a way to enumerate all permutations of a set of items in any reasonably standard python module.  (aka installed when I found out on the train). Of course this has been implemented many times before but I&#8217;m sharing it anyway :)
A set of n items has n! permutations. [...]]]></description>
			<content:encoded><![CDATA[<p>To my shock, I didn&#8217;t find a way to enumerate all permutations of a set of items in any reasonably standard python module.  (aka installed when I found out on the train). Of course this has been implemented many times before but I&#8217;m sharing it anyway :)<br />
A set of n items has n! permutations. Simple factorial implementation (seems also nowhere to be found in the standard python libs or numpy):</p>
<pre>def factorial(x):
    if x &lt; 0:
        raise ValueError("Factorial is only defined for x &gt;= 0")
    y = 1
    while x &gt;= 2:
        y *= x
        x -= 1
    return y</pre>
<p>Permutations can easily be defined recursively, but that limits you to sets of 1000 items (maximum recursion depth). So better to make an iterative function. Even better: instead of returning a list, use a generator so you don&#8217;t have to copy an array many times. This is also a perfect example of writing obfuscated code in a clean language like python.</p>
<pre>def permute(items, i):
    items = items[:]
    n = len(items)
    m = factorial(n)
    while n:
        c = (i%m) * n / m
        yield items[c]
        items.pop(c)
        m /= n
        n -= 1</pre>
<p>Example:</p>
<pre>&gt;&gt;&gt; import permute
&gt;&gt;&gt; items = [1,2,3]
&gt;&gt;&gt; for i in range(permute.factorial(len(items))):
...     print list(permute.permute(items, i))
...
[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 1, 2]
[3, 2, 1]</pre>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2007/11/10/traincoding-permutations-in-python/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Traincoding part one: per-thread global variables</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2007/11/04/traincoding-part-one-per-thread-global-variables/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2007/11/04/traincoding-part-one-per-thread-global-variables/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 14:04:06 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Traincoding</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2007/11/04/traincoding-part-one-per-thread-global-variables/</guid>
		<description><![CDATA[Update: keybuk points out that this is pretty useless and that you should read documentation instead.
Every day, I travel about 80 minutes to work and 80 minutes back, by public transport. This is rather boring but fortunately I usually have my laptop with me, so I can do some work or experiments. Last week I [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>Update</em></strong>: keybuk points out that this is pretty useless and that you should read <a href="http://gcc.gnu.org/onlinedocs/gcc/Thread_002dLocal.html#Thread_002dLocal">documentation</a> instead.</p>
<p>Every day, I travel about 80 minutes to work and 80 minutes back, by public transport. This is rather boring but fortunately I usually have my laptop with me, so I can do some work or experiments. Last week I started a little project I call traincoding: trying to accompish some small tasks while on the train. This is the first episode of the traincoding log.</p>
<p>Per-thread global variables</p>
<p>A simple way to make your library cumbersome to use in a threaded environment, is the use of global variables. They often have to be locked and unlocked, which costs quite a bit of time. If the global variables aren&#8217;t neccessarily global in the process but shared between functions (a good example is the infamous errno variable, which is thread-local by the way), the posix specification gives you something useful: <tt>pthread_setspecific</tt>. With this and some other functions from libpthread you can make an errno-like thread-local global variable.</p>
<p>In a modern glibc, errno is no longer an <tt>extern int errno;</tt> but a macro:</p>
<p><tt>#define errno (*__errno_location ())</tt></p>
<p>the <tt>__errno_location</tt> function finds out the thread-local address where errno is stored. This does not need <tt>pthread_getspecific</tt> since the C runtime allocates memory for errno explicitely. For our purposes we need to do our own allocation. Of course this is not limited to integers. The only thing we store is a pointer, the C runtime does not care what the pointer points to.</p>
<p>So, let&#8217;s define our macro first:</p>
<pre>#define my_var (*(__get_my_var_location()))</pre>
<p>The <tt>__get_my_var_location</tt> function now creates the key when it&#8217;s first called. It also allocates memory when it is first called in a specific thread:</p>
<pre>pthread_key_t __my_var_location;
pthread_once_t __my_var_init;

void __init_my_var(void) {
    pthread_key_create(&amp;__my_var_location, NULL);
}

int *__get_my_var_location(void) {
    void *ptr;
    (void) pthread_once(&amp;__my_var_init, __init_my_var);
    ptr = pthread_getspecific(__my_var_location);
    if(!ptr) {
        ptr = malloc(sizeof(my_var_t));
        pthread_setspecific(__my_var_location, ptr);
    }
    return (int*)ptr;
}</pre>
<p>That&#8217;s easy to use already, but having to type out 2 functions for every variable-like macro which you want to use this way is still a bit cumbersome, so why not let the C preprocessor do it for you? Here&#8217;s where it gets evil! You can download the code at the bottom as <a href="http://media.kaarsemaker.net/perthread.h">perthread.h</a> and simply use the following in your code (here&#8217;s a full test):</p>
<pre>#include
#include "perthread.h"

PER_THREAD(unsigned int, foo) /* NOTE: no semicolon! */
#define foo (*(__get_foo_location()))

static pthread_barrier_t barrier;
void *thread(void *arg) {
    foo = (unsigned int)pthread_self();
    printf("thread: %u foo: %un", (unsigned int)pthread_self(), foo);
    pthread_barrier_wait(&amp;barrier);
    printf("thread: %u foo: %un", (unsigned int)pthread_self(), foo);
    return NULL;
}

int main(int argc, char **argv) {
    pthread_t t1, t2, t3;
    void *res;

    pthread_barrier_init(&amp;barrier, NULL, 3);
    pthread_create(&amp;t1, NULL, thread, NULL);
    pthread_create(&amp;t2, NULL, thread, NULL);
    pthread_create(&amp;t3, NULL, thread, NULL);
    pthread_join(t1, &amp;res);
    pthread_join(t2, &amp;res);
    pthread_join(t3, &amp;res);

    return 0;
}</pre>
<p><tt>perthread.h</tt> contains the following <tt>PER_THREAD</tt> macro (you have to imagine a backslash at the endo of each line, wordpress messes it up):</p>
<pre>#define PER_THREAD(type, name)
static pthread_once_t __ ## name ## _init = PTHREAD_ONCE_INIT;
static pthread_key_t __ ## name ## _location;
void __init_ ## name (void) {
    pthread_key_create(&amp;__ ## name ## _location, free);
}
int *__get_ ## name ## _location(void) {
    void *ptr;
    (void) pthread_once(&amp;__ ## name ## _init, __init_ ## name);
    ptr = pthread_getspecific(__ ## name ## _location);
    if(!ptr) {
        ptr = malloc(sizeof(type));
        pthread_setspecific(__ ## name ## _location, ptr);
    }
    return (type*)ptr;
}</pre>
<p>This macro takes care of creating your initialization function and <tt>get_location</tt> function, all with the correct type and name. To see that it&#8217;s correct, run it through the C preprocessor.</p>
<p>That&#8217;s part one of traincoding. See you next time!
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2007/11/04/traincoding-part-one-per-thread-global-variables/feed/</wfw:commentRss>
		</item>
		<item>
		<title>End of an era, beginning of another</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2007/10/31/end-of-an-era-beginning-of-another/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2007/10/31/end-of-an-era-beginning-of-another/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 17:26:34 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Ubuntu</category>

		<category>Personal</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2007/10/31/end-of-an-era-beginning-of-another/</guid>
		<description><![CDATA[Back in 2005, when Ubuntu was still young and #ubuntu small (less than 300 users), I became Ubuntu member and IRC operator. At the latest Ubuntu release the channel peaked at over 1600 and usually has more than 1200 users. It&#8217;s been fantastic to see this growth in #ubuntu and related channels.
In the past 3 [...]]]></description>
			<content:encoded><![CDATA[<p>Back in 2005, when Ubuntu was still young and #ubuntu small (less than 300 users), I became Ubuntu member and IRC operator. At the latest Ubuntu release the channel peaked at over 1600 and usually has more than 1200 users. It&#8217;s been fantastic to see this growth in #ubuntu and related channels.</p>
<p>In the past 3 years it&#8217;s been a fun ride from Ubuntu user/channel visitor in 2004, through IRC op, and then representative of Ubuntu on freenode. Earlier this year we have worked on a more formal IRC governance, resulting in an IRC council of which I have been a proud member.</p>
<p>But today that has all come to an end, I have resigned from the council and have placed the responsibility for Ubuntu&#8217;s presence on freenode in the caring hands of the other council members. The IRC community is a vital part of the community and is in good shape, it is time for me to do the same for my other big love inside the Ubuntu community: the dutch locoteam.</p>
<p>Founded in 2004, the dutch locoteam it is one of the oldest locoteams around and has seen a steady growth over the past years. We have many forum contributors and a good crew of active people, it is time to turn this enthousiastic group of people into a professional team of Ubuntu supporters.</p>
<p>We&#8217;re halfway there already, <a href="http://www.ubuntu-nl.org/ubuntu-nl/wieiswie/">the active members</a> all have great ideas on how to move forward and lots of progress has been made already. The best part so far of this is the AWESOME release party we had last saturday, we estimate the number of visitors at over 400!</p>
<p>On to 2008, the year of Ubuntu-NL!
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2007/10/31/end-of-an-era-beginning-of-another/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Lwn becoming uwn?</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2007/10/26/lwn-becoming-uwn/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2007/10/26/lwn-becoming-uwn/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 13:53:11 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Uncategorized</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2007/10/26/lwn-becoming-uwn/</guid>
		<description><![CDATA[Is it just me or is lwn slowly turning into &#8220;Ubuntu weekly news&#8221;? It looks like  all details of Ubuntu development are important enough to mention. I&#8217;m an Ubuntu fan and I like seeing Ubuntu getting press coverage, but this is ridiculous. This particular announcement is only important for developers, not for Ubuntu end users [...]]]></description>
			<content:encoded><![CDATA[<p>Is it just me or is lwn slowly turning into &#8220;Ubuntu weekly news&#8221;? It looks like  <a href="http://lwn.net/Articles/255966/">all details</a> of Ubuntu development are important enough to mention. I&#8217;m an Ubuntu fan and I like seeing Ubuntu getting press coverage, but this is ridiculous. This particular announcement is only important for developers, not for Ubuntu end users and completely irrelevant to the general public. I&#8217;d rather see some news about the upcoming fedora 8 (yay gimp 2.4) or what&#8217;s going on with opensolaris&#8230;
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2007/10/26/lwn-becoming-uwn/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The ultimate password manager</title>
		<link>http://blogs.ubuntu-nl.org/dennis/2007/10/24/the-ultimate-password-manager/</link>
		<comments>http://blogs.ubuntu-nl.org/dennis/2007/10/24/the-ultimate-password-manager/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 09:04:34 +0000</pubDate>
		<dc:creator>Dennis Kaarsemaker</dc:creator>
		
		<category>Personal</category>

		<guid isPermaLink="false">http://blogs.ubuntu-nl.org/dennis/2007/10/24/the-ultimate-password-manager/</guid>
		<description><![CDATA[I hate passwords. Thoroughly. I always forget them, so I tried several password managers but I don&#8217;t really like any of them. Revelation is the nicest so far, but it misses some flexibility. Ideally, a password manager would be just an editor that saves files encrypted, so I tried mped which seems to be able [...]]]></description>
			<content:encoded><![CDATA[<p>I hate passwords. Thoroughly. I always forget them, so I tried several password managers but I don&#8217;t really like any of them. Revelation is the nicest so far, but it misses some flexibility. Ideally, a password manager would be just an editor that saves files encrypted, so I tried mped which seems to be able to do that. Not liking it, I hate using yet another editor. Wait&#8230; yet another editor&#8230;?</p>
<p>At that point I slapped myself in the head for overlooking the obvious solution for the ultimate password manager: vim. It is my editor of choice and can be scripted. 2 lines in ~/.vimrc and it&#8217;s the ultimate password editor, allowing you to encrypt everything with gpg easily. Only two passwords left to remember: user account and gpg key. Profit.</p>
<pre>map &lt;F12&gt; &lt;Esc&gt;:%!gpg --encrypt --armor --recipient dennis@kaarsemaker.net&lt;CR&gt;&lt;CR&gt;&lt;C-l&gt;
map &lt;S-F12&gt; &lt;Esc&gt;:%!gpg --decrypt 2&gt;/dev/null&lt;CR&gt;&lt;CR&gt;&lt;C-l&gt;</pre>
<p>F12 now encrypts and Shifs+F12 decrypts. Yay!</p>
<p><strong>Update:</strong> <a href="http://blogs.ubuntu-nl.org/dennis/2007/10/24/the-ultimate-password-manager/#comment-48784">it can be done even nicer</a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.ubuntu-nl.org/dennis/2007/10/24/the-ultimate-password-manager/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
