<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

    <title>Jon Bernard</title>
    <link href="http://tuxion.com/feeds/index.xml" rel="self"/>
    <link href="http://tuxion.com/"/>
    <updated>2016-08-03T09:00:21-04:00</updated>
    <id>http://tuxion.com/</id>
    <author>
        <name>Jon Bernard</name>
        
    </author>

    
        <entry>
            <title>A Specific Module</title>
            <link href="http://tuxion.com/2013/09/15/specific-module.html"/>
            <updated>2013-09-15T00:00:00-04:00</updated>
            <id>http://tuxion.com/2013/09/15/specific-module</id>
            <content type="html">&lt;p&gt;I'm sure you're chomping at the bit to compile kernel modules.  Certainly the
simplest way is to build a kernel from source, which will compile all of the
requested modules in the process.&lt;/p&gt;

&lt;p&gt;But what if you don't want to build the entire kernel?  Instead you'd like to
just build a single module in the source tree without building the whole damn
thing.  Why would you do this?  Perhaps your vendor did not include a needed
module in their stock kernel.  Or perhaps you intend to send a patch to a linux
kernel driver and you would like to test it before submission.  Or perhaps you
have an ancient laptop that can barely handle browsing the web without needing
more RAM and making you scream and throw things all while trying to not draw
attention to yourself in the coffee shop.&lt;/p&gt;

&lt;p&gt;Whatever the reason, here's how to do it:&lt;/p&gt;

&lt;p&gt;First, configure the kernel to build everything as a module:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;make allmodconfig
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;There are several ways to configure the linux kernel, but if you only intend to
build a single module then this is probably what you want.  You may already have
a &lt;code&gt;.config&lt;/code&gt; in your source tree and so you can skip this step.  If not, you
certainly will after you run the above command.&lt;/p&gt;

&lt;p&gt;Then you must prepare the build environment:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;make modules_prepare
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once that command completes, you're ready to build a module!  The command is
simple, you need only know the subdirectory that holds the module you want to
build.  For instance, say I would like to build the newly added fwserial module
(TTY over FireWire).  The source for the module lives in
&lt;code&gt;drivers/staging/fwserial&lt;/code&gt;.  So the appropriate command to build only that
module would be:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;make M=drivers/staging/fwserial
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can replace my hypothetical path to fwserial with whatever you want.  After
compilation completes, you could find this module at
&lt;code&gt;drivers/staging/fwserial/fwserial.ko&lt;/code&gt;.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Decoding Hexidecimal Strings</title>
            <link href="http://tuxion.com/2013/07/16/hexidecimal-decoding.html"/>
            <updated>2013-07-16T00:00:00-04:00</updated>
            <id>http://tuxion.com/2013/07/16/hexidecimal-decoding</id>
            <content type="html">&lt;p&gt;I was looking through job postings today and I came across a &lt;a href=&quot;https://lovewithfood.com/&quot;&gt;LoveWithFood&lt;/a&gt;
posting that really got my attention.  Not the posting itself so much (although
the &lt;a href=&quot;https://jobs.github.com/positions/e9eb9794-e03e-11e2-8938-e514bfa3f35b&quot;&gt;job&lt;/a&gt; looks really cool), but because they included a small programming
question &lt;em&gt;inside&lt;/em&gt; the post.  It was a hexadecimal-encoded string that contained
a message that should be decoded and included in the job submission.  The
encoded string is this:&lt;/p&gt;

&lt;pre&gt;e299a5205765204d616b652054756d6d792048617070792120e299a5&lt;/pre&gt;


&lt;p&gt;I don't know about you, but I love secret messages.  I just couldn't help
myself.&lt;/p&gt;

&lt;p&gt;In python, this is really easy because it has &lt;code&gt;encode()&lt;/code&gt; and &lt;code&gt;decode()&lt;/code&gt; that
both take a format as a parameter.  So the quick solution is this:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mystring&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;e299a5205765204d616b652054756d6d792048617070792120e299a5&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mystring&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'hex'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;But that's really boring.  And &lt;code&gt;decode()&lt;/code&gt; gets to do all of the work, so I set
out to implement the decode operation on my own (in python), and I made some
interesting discoveries along the way.&lt;/p&gt;

&lt;h2&gt;Character Encoding&lt;/h2&gt;

&lt;p&gt;Let me first explain what I've learned about character encoding.  Well, there is
too much to explain, so let me sum up.  You're certainly familiar with
&lt;a href=&quot;http://en.wikipedia.org/wiki/ASCII&quot;&gt;ASCII&lt;/a&gt;, which is a 7-bit encoding scheme developed by the U.S. to
represent character symbols.  This means only 128 unique characters can be
represented and this is an obvious problem for languages that don't share our
relatively small alphabet.&lt;/p&gt;

&lt;p&gt;So &lt;a href=&quot;https://en.wikipedia.org/wiki/Unicode&quot;&gt;unicode&lt;/a&gt; was created to solve this problem.  Unicode is a standard,
but not an implementation.  &lt;a href=&quot;https://en.wikipedia.org/wiki/UTF-8&quot;&gt;Utf-8&lt;/a&gt; is a unicode implementation that uses
32 bits to represent character symbols (some of the higher bits aren't used but
that's beyond this post).  Utf-8 will use fewer bytes if it can, so not all
characters encode to a 32 bit value.  One neat fact is that utf-8 uses the same
byte value for ASCII characters which has the same value as ASCII encoding, so
the character values are the same.&lt;/p&gt;

&lt;p&gt;Let's take a look at a few examples:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'a'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'hex'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'61'&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'é'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'hex'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'c3a9'&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'…'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'hex'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;s&quot;&gt;'e280a6'&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;I just glossed over a huge amount of information, but bear with me.  The basic
gist is this:  given a long hexadecimal-encoded string, decoding it means
breaking it apart into individual bytes and decoding each byte by itself.  In
some cases, decoding a particular byte may require the value of the previous
byte.  Since a byte is represented as two hexadecimal digits, we need to
separate the string into pairings and decode each pairing.&lt;/p&gt;

&lt;h2&gt;Decoding without decode()&lt;/h2&gt;

&lt;p&gt;In the encoded string we are given, each pair of two characters contains the
encoding for a single printable character, so the goal is to separate this large
array into pairings of two that we can individually decoded and then combine to
see the final result.&lt;/p&gt;

&lt;h3&gt;Python's :: array syntax&lt;/h3&gt;

&lt;p&gt;Python provides a really powerful array index notation that allows you to
quickly slice and dice an array with very little effort.  One of these is the
&lt;code&gt;::&lt;/code&gt; operator which allows you to &lt;em&gt;take&lt;/em&gt; each nth entry starting at some
starting point.  So, for example, if you wanted to pull out all of the
even-indexed elements in an array called &lt;code&gt;A&lt;/code&gt; you would say &lt;code&gt;A[0::2]&lt;/code&gt;.  That is,
starting at index 0, take every second element.  You can get the odd-indexed
elements by changing the start index to 1 like so: &lt;code&gt;A[1::2]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This allows us to separate the large array &lt;code&gt;A&lt;/code&gt; into two smaller arrays &lt;code&gt;B&lt;/code&gt; and
&lt;code&gt;C&lt;/code&gt; with the following propery: at each index &lt;code&gt;i&lt;/code&gt; from 0 to n, &lt;code&gt;B[i]&lt;/code&gt; and &lt;code&gt;C[i]&lt;/code&gt;
contain the two characters we want to pair together.  If only there was a way to
&lt;em&gt;zip&lt;/em&gt; the two arrays together...&lt;/p&gt;

&lt;h3&gt;The zip() function&lt;/h3&gt;

&lt;p&gt;Of course python has a &lt;code&gt;zip()&lt;/code&gt; function, which does exactly what we want.
Here's the documented definition:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Return a list of tuples, where each tuple contains the i-th element from each
of the argument sequences.  The returned list is truncated in length to the
length of the shortest argument sequence.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;p&gt;So acquiring a set of tuples that we can then decode individually is as simple
as:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'e2'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'99'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'a5'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'20'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'57'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'65'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'20'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'4d'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'61'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'6b'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'65'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'20'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'54'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'75'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'6d'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'6d'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'79'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'20'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'48'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'61'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'70'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'70'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'79'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'21'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'20'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'e2'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'99'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'a5'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;The above is a list comprehension and is one of the many features that make
Python a joy to work with.  If you're not familiar with list comprehensions,
I highly encourage you to learn more about them.&lt;/p&gt;

&lt;p&gt;Now that we can take the string apart into pieces, it's easy to convert each
byte to decimal:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;226&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;153&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;165&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;87&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;77&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;97&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;107&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;117&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;72&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;97&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;112&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;112&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;33&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;226&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;153&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;165&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;And now we can interpret each decimal value as a character:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;chr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xe2&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x99&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xa5&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'W'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'e'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'M'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'a'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'k'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'e'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'T'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'u'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'m'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'m'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'y'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'H'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'a'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'p'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'p'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'y'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'!'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;' '&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xe2&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x99&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xa5&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;And now the message is starting to show.  It appears there are unicode
characters at the beginning and end of the string.  The &lt;code&gt;print&lt;/code&gt; function knows
how to correctly interpret those sequences, so decoding the string is now:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;chr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])])&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;♥&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;We&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Make&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Tummy&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Happy&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;♥&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;So there you have it.  Decoding secret messages is fun, but I think the really
cool part is the use of the &lt;code&gt;::&lt;/code&gt; array index operator, the &lt;code&gt;zip&lt;/code&gt; function, and
python's list comprehensions.&lt;/p&gt;

&lt;h3&gt;What about Ruby?&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&quot;https://jobs.github.com/positions/e9eb9794-e03e-11e2-8938-e514bfa3f35b&quot;&gt;job&lt;/a&gt; requested the answer in Ruby, and it turns out the answer is not
so different from what we've just done in Python.  Here is a Ruby solution:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-ruby&quot; data-lang=&quot;ruby&quot;&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;INPUT&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;e299a5205765204d616b652054756d6d792048617070792120e299a5&quot;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;e299a5205765204d616b652054756d6d792048617070792120e299a5&quot;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/../&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;e2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;99&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;a5&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;57&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;65&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;4d&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;61&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;6b&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;65&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;54&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;75&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;6d&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;6d&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;79&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;48&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;61&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;70&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;70&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;79&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;21&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;20&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;e2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;99&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;a5&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/../&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:hex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;226&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;153&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;165&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;87&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;77&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;97&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;107&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;101&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;84&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;117&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;109&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;72&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;97&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;112&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;112&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;121&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;33&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;226&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;153&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;165&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/../&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:hex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:chr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xE2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x99&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xA5&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;W&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;e&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;M&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;k&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;e&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;T&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;u&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;m&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;m&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;y&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;H&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;p&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;p&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;y&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xE2&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x99&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xA5&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/../&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:hex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:chr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xE2\x99\xA5&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; We Make Tummy Happy! &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\xE2\x99\xA5&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;INPUT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scan&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/../&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:hex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:chr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;♥&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;We&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Make&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Tummy&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Happy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;♥&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;In the absense of &lt;code&gt;decode()&lt;/code&gt;, I personally find the Ruby solution to be more
concise.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>The GPL and Derived Works</title>
            <link href="http://tuxion.com/2012/12/10/derived-works.html"/>
            <updated>2012-12-10T00:00:00-05:00</updated>
            <id>http://tuxion.com/2012/12/10/derived-works</id>
            <content type="html">&lt;p&gt;For the longest time I thought I had a decent understanding of what constitutes
a derived work of source code released under the GPL.  I work with GPL code
every day, so it's a concept that I generally take for granted.  My personal
view is that any influence from GPL source, whether directly copying it into
your text editor or reading it carefully and then reproducing it in some form is
considered a derived work (for &lt;em&gt;my&lt;/em&gt; definition of &quot;derived&quot;).&lt;/p&gt;

&lt;p&gt;I realize my position is a bit extreme, but I thought this was the general
consensus.  For any creation, I feel all influences and sources should be duly
credited.  If properly crediting a source means releasing your creation under
the GPL, then it's the right thing to do.  If this conclusion is unacceptable,
then the problem must be solved independently without the use of information
contained in relevant GPL solutions.  Those are the two conclusions that I see
for how to properly conduct myself as a software creator.&lt;/p&gt;

&lt;p&gt;But this view is not entirely accurate.&lt;/p&gt;

&lt;p&gt;It turns out, what constitutes a derived work is much more vague than
I imagined.  Having been an employee of companies that create and sell
proprietary software, this same issue comes up every now and then: &quot;I know
I cannot just copy the code, but what if I read it and think about it, and then
create a solution that's similar?&quot;  The answer to this question seems obvious to
me, but as I've learned recently, it's actually a very difficult question to
answer.&lt;/p&gt;

&lt;p&gt;The GPL does not define exactly what a derived work is, which leads to the
ambiguity in question.  So I contacted the Free Software Foundation and got the
following response:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In fact, the issue has nothing to do with the GPL per-se, but about copyright
law in general.  For example, If I read an interesting book and am inspired to
write one myself, should that new book be considered a derivative?  Ultimately,
this is something that only a court of law can decide.  There are methods to
help reduce the risk of legal trouble when writing software based on
foreknowledge of some other code, but those are context dependent.&lt;/p&gt;

&lt;cite&gt; Yoni Rabkin, Free Software Foundation&lt;/cite&gt;
&lt;/blockquote&gt;


&lt;p&gt;As much as I hate it, the answer seems to be &quot;it depends on context&quot;, rather
than black and white.  I don't intend to change the way I conduct myself
personally, but it is nice to have a better understanding of the issue.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Logging to the Serial Console</title>
            <link href="http://tuxion.com/2012/07/19/serial-logging.html"/>
            <updated>2012-07-19T00:00:00-04:00</updated>
            <id>http://tuxion.com/2012/07/19/serial-logging</id>
            <content type="html">&lt;p&gt;There are several ways to capture kernel log output on a remote machine. One way
is to configure the kernel to use a serial port as console. If you have
a machine that has a serial port, or you're running a VM, this method can be
very helpful in capturing kernel log data when a panic occurs.&lt;/p&gt;

&lt;p&gt;On Debian (or Ubuntu) this is really easy to setup. Simply edit
&lt;code&gt;/etc/default/grub&lt;/code&gt; and change the line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash&quot;&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;to:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;GRUB_CMDLINE_LINUX_DEFAULT=&quot;console=tty0 console=ttyS0,115200n8 debug ignore_loglevel&quot;&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;and then execute:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;update-grub&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;and reboot. Let's examine this a bit closer:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console=tty0&lt;/code&gt; instructs the kernel to continue using the standard console
device so you'll still see the usual boot messages on an attached monitor.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console=ttyS0,&lt;/code&gt; instructs the kernel to also
use the first serial device as a console. If you have multiple serial ports, you
can change the number to match the device you wish to use.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;115200n8&lt;/code&gt; sets the serial speed to 115200 bits per second with no parity and
8 data bits per character. The other end of the serial line must be configured
to match these settings.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;debug ignore_loglevel&lt;/code&gt; allows you to see ALL kernel messages on the configured
console(s). If you're trying to debug your kernel, you will most certainly want
this.&lt;/p&gt;

&lt;p&gt;If your machine is running in a VM, the management utility likely has
a configuration that will allow you to write the console data to a file on the
host machine. If you intend to use a real serial port and cable, you can use any
serial communication program. I use &lt;code&gt;minicom&lt;/code&gt;, the command I use is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;minicom -D /dev/ttyUSB0 -b 115200n8 -m -o -w&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;I use a serial-to-usb converter as my laptop does not have a proper serial port.
This device communicates on &lt;code&gt;/dev/ttyUSB0&lt;/code&gt;. See the manpage for minicom for
additional options.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Scrolling Log Output</title>
            <link href="http://tuxion.com/2012/06/10/scrolling-log-output.html"/>
            <updated>2012-06-10T00:00:00-04:00</updated>
            <id>http://tuxion.com/2012/06/10/scrolling-log-output</id>
            <content type="html">&lt;p&gt;Related to the earlier article on &lt;a href=&quot;/2012/05/29/linux-kernel-development.html&quot;&gt;kernel
development&lt;/a&gt;, here's one thing that
I find very useful.  During development I often compile, load, unload, modify,
and recompile in a loop.  I rarely do this on my development machine but rather
in a VM or on a nearby test machine.  It's a pain to keep typing &lt;code&gt;dmesg&lt;/code&gt; all the
time.  So I keep a separate terminal open with &lt;code&gt;dmesg&lt;/code&gt; running in a loop.
Actually it's a split pain within Tmux, but that's not important &lt;em&gt;yet&lt;/em&gt;.  Here's
what I do.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;while true; do sudo dmesg -c | tee -a /tmp/dmesg.log; sleep 1; done&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;With this running in it's own terminal, you can now immediately see the effect
of a module load or unload without having to go through the tedium of typing
&lt;code&gt;dmesg&lt;/code&gt; and figuring out what's been added since the last invocation.  I find
this quite helpful.&lt;/p&gt;

&lt;p&gt;Also, &lt;code&gt;tee&lt;/code&gt; is a really useful tool, read up on it if you haven't already.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Linux Kernel Development</title>
            <link href="http://tuxion.com/2012/05/29/linux-kernel-development.html"/>
            <updated>2012-05-29T00:00:00-04:00</updated>
            <id>http://tuxion.com/2012/05/29/linux-kernel-development</id>
            <content type="html">&lt;p&gt;My intent with this, and related articles to come, is to explain how I develop
software that runs as part of the Linux kernel.  Not so much the way my code
works, but rather the tools, configuration, and techniques that allow me to
create kernel code quickly (within reason).&lt;/p&gt;

&lt;p&gt;My hope is that you can use some of these ideas to bring you closer to doing
actual work, and spend less time monkeying around with your environment.  Or at
least this can serve as a reference so I don't keep reinventing every wheel
I come across.&lt;/p&gt;

&lt;p&gt;Techniques like testing your module within UML (Usermode Linux) so you don't
destroy your machine when things go wrong, or how to use objdump and some basic
algebra to determine exactly where an oops occurred in a given piece of code.
Perhaps we could cover common bit-shift operations and how they're used to save
computational resources.  These and other basic debugging tools can help you
navigate the world of kernel development more quickly and increase productivity
immensely.&lt;/p&gt;

&lt;p&gt;This exercise will walk you through creating a simple module, compiling it,
loading it into your running kernel, and verifying that it has been loaded.
This is the most basic form of the Modify-Compile-Test loop that allows you to
begin to iterate over a piece of code.  Also, I have to get this intro stuff out
of the way so I can later talk about things that build upon it.&lt;/p&gt;

&lt;p&gt;I assume a good general understanding of the Linux ecosystem as well
a proficiency in C and other related tools like &lt;code&gt;make&lt;/code&gt;, &lt;code&gt;gdb&lt;/code&gt;, and &lt;code&gt;vim&lt;/code&gt; (or
something equivalent).&lt;/p&gt;

&lt;h2&gt;Your First Module&lt;/h2&gt;

&lt;p&gt;Create a directory to hold your kernel source&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ mkdir ~/my-module
$ cd ~/my-module
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Let's start with a boilerplate makefile. Put the following in your &lt;code&gt;Makefile&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ifneq ($(KERNELRELEASE),)

        obj-m += my-module.o

else

        KERNELDIR ?= /lib/modules/$(shell uname -r)/build
        PWD := $(shell pwd)

all: my-module

%.o: %.c
        @echo &quot;  CC      $&lt;&quot;
        @$(CC) -D_GNU_SOURCE -ggdb3 -Wall -Wextra -I. -c $&lt; -o $@

my-module:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

tags: my-module.c
        @echo &quot;  GEN     $@&quot;
        @ctags -R

clean:
        $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
        rm -f *.o tags

endif
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Make sure to preserve the indentation using tabs or &lt;code&gt;make&lt;/code&gt; will complain.&lt;/p&gt;

&lt;p&gt;The above makefile gives you three targets. An &lt;code&gt;all&lt;/code&gt; target (just typing &lt;code&gt;make&lt;/code&gt;
will launch this) that builds your module. A &lt;code&gt;tags&lt;/code&gt; target that will generate
a ctags file of all the source code contained in your directory.  Vim will pick
this up automatically and allow you to jump to tags from within your editor.
This is a must-have feature.  And a &lt;code&gt;clean&lt;/code&gt; target that will remove any
auto-generated files.&lt;/p&gt;

&lt;p&gt;Another nice thing about this makefile is that it can be referenced within the
kernel tree itself, or it can be used to build an out-of-tree module.  For this
exercise, we will build an out-of-tree module, meaning we're not building our
code as part of a larger kernel compile.  This code will be built against the
headers for the running kernel and produce just a kernel module that can be
inserted into the running kernel.&lt;/p&gt;

&lt;p&gt;We create a simple test module in &lt;code&gt;my-module.c&lt;/code&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#include &amp;lt;linux/module.h&amp;gt;

#define AUTHOR      &quot;My Name &amp;lt;me@some-host.com&amp;gt;&quot;
#define LICENSE     &quot;GPL&quot;

static int __init my_module_init(void)
{
        printk(KERN_INFO &quot;ZOMG I'M ALIVE ! ! !\n&quot;);
        return 0;
}

static void __exit my_module_exit(void)
{
        printk(KERN_INFO &quot;We've been hit captain, abandon ship!\n&quot;);
}

module_init(my_module_init);
module_exit(my_module_exit);

MODULE_AUTHOR(AUTHOR);
MODULE_LICENSE(LICENSE);
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You'll likely need to fix the single and double quotes if you're pasting into
your editor from the browser.&lt;/p&gt;

&lt;p&gt;Building a kernel module from this should be as simple as&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ make&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If this fails, make sure you have the headers for the currently running kernel
installed on your system.&lt;/p&gt;

&lt;p&gt;Upon successful compilation, load the resulting module into your kernel&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ sudo insmod ./my-module.ko&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If the prompt returns with no error message, you're good to go.  The kernel logs
informational messages to a ring buffer that can be accessed with &lt;code&gt;dmesg&lt;/code&gt;.  You
should see your init string contained in the output of that command.&lt;/p&gt;

&lt;p&gt;The module is removed from the kernel with&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ sudo rmmod my-module&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The output of &lt;code&gt;dmesg&lt;/code&gt; should now contain your exit string.&lt;/p&gt;

&lt;p&gt;It's important to note that &lt;code&gt;rmmod&lt;/code&gt; does not guarantee you return to the state
before the module was loaded.  The code you compiled and loaded is executed
within the context of the kernel and not within any sort of sandboxed
environment.  This means that any public data within the kernel could have been
modified.  It is not always the case that a module cleans up after itself
properly, so although &lt;code&gt;rmmod&lt;/code&gt; succeeded, you may still require a reboot to
return to a sane running state.&lt;/p&gt;

&lt;p&gt;The above is essentially what you'll read an any Linux development book. Nothing
special, but it's the most basic foundation so I feel it's worth covering.
Everything builds on this first step.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Get More Out of Vim's makeprg</title>
            <link href="http://tuxion.com/2011/09/30/vim-makeprg.html"/>
            <updated>2011-09-30T00:00:00-04:00</updated>
            <id>http://tuxion.com/2011/09/30/vim-makeprg</id>
            <content type="html">&lt;p&gt;This started out as a small post on how to preview markdown documents in Vim
using &lt;code&gt;makeprg&lt;/code&gt;, but somehow I got carried away.  More on the markdown thing in
a bit.&lt;/p&gt;

&lt;p&gt;When you type &lt;code&gt;:make&lt;/code&gt; in Vim, the value of &lt;code&gt;makeprg&lt;/code&gt; is executed in
a subprocess.  Traditionally this value is set to &lt;em&gt;make&lt;/em&gt;, but you can set this
to anything you like. You can see the current value by typing &lt;code&gt;:set makeprg&lt;/code&gt;.
When you combine this with Vim's support for filetype plugins, there's
a decent amount of value that I think is sometimes overlooked.  So this
article is an attempt to explain some of the things you can do with &lt;em&gt;makeprg&lt;/em&gt;
and filetype detection.&lt;/p&gt;

&lt;h2&gt;Filetype Plugins&lt;/h2&gt;

&lt;blockquote&gt;&lt;p&gt;A filetype plugin is like a global plugin, except that it sets options and
defines mappings for the current buffer only.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;In order to make use of filetype plugins, vim must be told to enable this
feature.  This is enabled by default on many installations, but some (perhaps
MacOS X) require the user to enable it explicitly.  Place this line in your
&lt;code&gt;vimrc&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;filetype plugin on&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Using a filetype plugin, we can set &lt;code&gt;makeprg&lt;/code&gt; to something useful depending on
the type of a file it happens to be.  Adding your own filetype plugin is easy,
just create a file of the form: &lt;code&gt;&amp;lt;filetype&amp;gt;.vim&lt;/code&gt; inside the
&lt;code&gt;~/.vim/after/ftplugin&lt;/code&gt; directory.  The &lt;em&gt;after&lt;/em&gt; subdirectory is technically
optional, but I prefer it as it keeps things isolated from other installed
plugins.  The &lt;em&gt;after&lt;/em&gt; subdirectory is sourced last as Vim initializes itself,
so putting your options there ensures they aren't clobbered by other plugins.&lt;/p&gt;

&lt;p&gt;For a given Vim buffer, you can see the filetype by typing &lt;code&gt;:set ft&lt;/code&gt;. Some
people put this information in their statusline, which can be helpful if
you're writing Vim plugins or just want to make sure things are being detected
correctly.&lt;/p&gt;

&lt;p&gt;For example, if I want to define custom settings for the &lt;em&gt;C&lt;/em&gt; filetype, I would
create &lt;code&gt;~/.vim/after/ftplugin/c.vim&lt;/code&gt; and put my settings there.  Any time
a file of type &lt;em&gt;C&lt;/em&gt; is loaded, my settings are applied. We can use this
mechanism to set a custom &lt;code&gt;makeprg&lt;/code&gt; for certain filetypes.&lt;/p&gt;

&lt;h2&gt;Customizing makeprg for Markdown&lt;/h2&gt;

&lt;p&gt;I take all of my notes in
&lt;a href=&quot;http://daringfireball.net/projects/markdown/&quot;&gt;Markdown&lt;/a&gt;, which is nearly
plain text with a tiny amount of markup.  This allows me to quickly convert my
personal notes into decent looking html documentation.  It seems to be a regular
occurrence that my notes become the initial documentation for the project or
subproject that I'm working on.  Many wiki's support Markdown, so it ends up
saving me work by just keeping everything in that format.&lt;/p&gt;

&lt;p&gt;Even though Markdown's syntax is very lean and simple, I still end up
forgetting some of it from time to time.  I find it useful to generate and
view the HTML output for the buffer that I'm working on periodically to make
sure things look right.  This is really easy by setting a custom &lt;code&gt;makeprg&lt;/code&gt; for
the markdown filetype.&lt;/p&gt;

&lt;h3&gt;The Hammer Plugin&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/robgleeson&quot;&gt;Robert Gleeson&lt;/a&gt; wrote a Vim plugin called
&lt;a href=&quot;https://github.com/robgleeson/hammer.vim&quot;&gt;Hammer&lt;/a&gt; that basically does exactly
what I explain here and quite a bit more.  It might be perfect for you, but
for me it's much more than I need.  I've had
&lt;a href=&quot;https://github.com/robgleeson/hammer.vim/issues/11&quot;&gt;problems&lt;/a&gt; when the
version of Ruby on the system is not the same as what Vim was compiled with.
Check it out though, you might love it.&lt;/p&gt;

&lt;h3&gt;A Simpler Approach&lt;/h3&gt;

&lt;p&gt;All I want is to type &lt;code&gt;:make&lt;/code&gt; and have Vim generate an HTML version in &lt;code&gt;/tmp&lt;/code&gt;
that I can point my browser to. So I put the following in
&lt;code&gt;~/.vim/after/ftplugin/markdown.vim&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-vim&quot; data-lang=&quot;vim&quot;&gt;&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; makeprg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;redcarpet\ %\ &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/tmp/&lt;/span&gt;%&lt;span class=&quot;p&quot;&gt;&amp;lt;.&lt;/span&gt;html&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;Let's take a quick look at what's going on here:&lt;/p&gt;

&lt;ul class=&quot;square&quot;&gt;

    &lt;li&gt;The above setting is applied only when editing a markdown buffer.
    Personally, I use
    &lt;a href=&quot;https://github.com/tanoku/redcarpet&quot;&gt;redcarpet&lt;/a&gt; to parse
    markdown, but there are many others that you can substitute here.&lt;/li&gt;

    &lt;li&gt;Spaces in option strings must be escaped so Vim knows when to stop
    parsing.&lt;/li&gt;

    &lt;li&gt;% expands to the name of the file currently being edited.&lt;/li&gt;

    &lt;li&gt;%&lt; expands to the name of the file without the trailing extension.
    This allows us to change the name of the file and add the html
    extension.&lt;/li&gt;

&lt;/ul&gt;


&lt;p&gt;So the above command calls &lt;code&gt;redcarpet&lt;/code&gt; on the filename and redirects the
output to &lt;code&gt;/tmp/&amp;lt;filename&amp;gt;.html&lt;/code&gt;.  That's it, super simple.  Once this
completes, I point my browser to &lt;code&gt;file:/tmp&lt;/code&gt; and load the file I'm interested
in.&lt;/p&gt;

&lt;p&gt;This same approach can be taken with &lt;strong&gt;ReStructured Text&lt;/strong&gt; by putting the
following in &lt;code&gt;~/.vim/after/ftplugin/rst.vim&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-vim&quot; data-lang=&quot;vim&quot;&gt;&lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; makeprg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;rst2html&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;py&lt;/span&gt;\ %\ &lt;span class=&quot;sr&quot;&gt;/tmp/&lt;/span&gt;%&lt;span class=&quot;p&quot;&gt;&amp;lt;.&lt;/span&gt;html`&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;h2&gt;Extra Credit&lt;/h2&gt;

&lt;p&gt;For &lt;em&gt;C&lt;/em&gt;, we could set &lt;code&gt;makeprg&lt;/code&gt; to call gcc directly instead of &lt;code&gt;make&lt;/code&gt; if
a Makefile is not found in the current working directory.  I find this very
helpful when creating a scratch source file to test certain behaviour or
a quick theory.  Here's what the contents of &lt;code&gt;~/.vim/after/ftplugin/c.vim&lt;/code&gt;
might look like:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-vim&quot; data-lang=&quot;vim&quot;&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;!&lt;/span&gt;filereadable&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;expand&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;%:p:h&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/Makefile&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;setlocal&lt;/span&gt; makeprg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;gcc\ &lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;Wall\ &lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;Wextra\ &lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;o&lt;/span&gt;\ %&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;\ %
&lt;span class=&quot;k&quot;&gt;endif&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;Now when you load a file of type &lt;em&gt;C&lt;/em&gt; and there is no Makefile, typing &lt;code&gt;:make&lt;/code&gt;
will compile your source file into an executable of the same name (minus the
extension).  I use this all the time.  You could do the same thing for C++ by
changing the filename to &lt;code&gt;cpp.vim&lt;/code&gt; and changing &lt;code&gt;gcc&lt;/code&gt; to &lt;code&gt;g++&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Future Work&lt;/h2&gt;

&lt;p&gt;It would be cool to copy the target filename to the clipboard for easy pasting
into the browser's URL bar.&lt;/p&gt;

&lt;h3&gt;Update&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;I handle this with the following&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-vim&quot; data-lang=&quot;vim&quot;&gt;&lt;span class=&quot;k&quot;&gt;setlocal&lt;/span&gt; makeprg&lt;span class=&quot;p&quot;&gt;=&lt;/span&gt;markdown\ %\ &lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;%&lt;span class=&quot;p&quot;&gt;&amp;lt;.&lt;/span&gt;html

&lt;span class=&quot;c&quot;&gt;&quot; Open corresponding html file&lt;/span&gt;
nmap &lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;Leader&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:!&lt;/span&gt;google&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt;chrome %&lt;span class=&quot;p&quot;&gt;&amp;lt;.&lt;/span&gt;html&lt;span class=&quot;p&quot;&gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;CR&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;which may be replaced by the browser and file position of your preference.&lt;/p&gt;
&lt;cite&gt;Bijan Chokoufe&lt;/cite&gt;
&lt;/blockquote&gt;

</content>
        </entry>
    
        <entry>
            <title>New GPG Key</title>
            <link href="http://tuxion.com/2010/07/20/new-gpg-key.html"/>
            <updated>2010-07-20T00:00:00-04:00</updated>
            <id>http://tuxion.com/2010/07/20/new-gpg-key</id>
            <content type="html">&lt;p&gt;I've recently set up a new GPG key, and will be transitioning away from my old
one. I have done this in order to migrate to a larger RSA key and stronger hash
functions, and NOT due to any known key compromise. The old key will continue
to be valid for some time, but future correspondence should use the new one
wherever possible.&lt;/p&gt;

&lt;p&gt;I have created a &lt;a href=&quot;http://people.debian.org/~jbernard/key-transition-2010-07-20.txt.asc&quot;&gt;transition
document&lt;/a&gt;
and signed it with both keys.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Don't Clobber Your Registers</title>
            <link href="http://tuxion.com/2010/07/02/clobber-registers.html"/>
            <updated>2010-07-02T00:00:00-04:00</updated>
            <id>http://tuxion.com/2010/07/02/clobber-registers</id>
            <content type="html">&lt;p&gt;I recently needed to call the &lt;code&gt;cpuid&lt;/code&gt; instruction from some C++ code. This is
&lt;a href=&quot;http://wikipedia.org/wiki/CPUID&quot;&gt;well documented on wikipedia&lt;/a&gt; and everything
went fine until I hit a snag moving the code from x86_64 to i386.&lt;/p&gt;

&lt;p&gt;It seems that &lt;code&gt;%ebx&lt;/code&gt; is the PIC register for i386, and so you must take care to
not clobber it when calling &lt;code&gt;cpuid&lt;/code&gt;. This is accompolished by explictly saving
and restoring the register before and after the call to &lt;code&gt;cpuid&lt;/code&gt;. An additional
step is required to tell gcc that &lt;code&gt;%ebx&lt;/code&gt; will not be clobbered by the call to
&lt;code&gt;cpuid&lt;/code&gt;. The last lines of assembly define which registers were potentially
clobbered so gcc can generate appropriate code. By manually saving and
restoring &lt;code&gt;%ebx&lt;/code&gt;, it can be saftely omitted from that list. I did not find any
information documenting this specifically, so here it is!  The following code
returns the result of &lt;code&gt;cpuid&lt;/code&gt; and runs on both x86_64 and i386.&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-c&quot; data-lang=&quot;c&quot;&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;cpuid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;regs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cpuid_leaf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ebx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ecx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;edx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;asm&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;volatile&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#if defined(&lt;strong&gt;i386&lt;/strong&gt;)
&lt;/span&gt;             &lt;span class=&quot;s&quot;&gt;&quot;pushl %%ebx;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;             &lt;span class=&quot;s&quot;&gt;&quot;movl %4, %%eax;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
             &lt;span class=&quot;s&quot;&gt;&quot;cpuid;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
             &lt;span class=&quot;s&quot;&gt;&quot;movl %%eax, %0;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
             &lt;span class=&quot;s&quot;&gt;&quot;movl %%ebx, %1;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
             &lt;span class=&quot;s&quot;&gt;&quot;movl %%ecx, %2;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
             &lt;span class=&quot;s&quot;&gt;&quot;movl %%edx, %3;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#if defined(&lt;strong&gt;i386&lt;/strong&gt;)
&lt;/span&gt;             &lt;span class=&quot;s&quot;&gt;&quot;popl %%ebx;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n\t&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;             &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;=m&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;=m&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ebx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;=m&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ecx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;=m&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;edx&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
             &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;r&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cpuid_leaf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
             &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%eax&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#if !defined(&lt;strong&gt;i386&lt;/strong&gt;)
&lt;/span&gt;             &lt;span class=&quot;s&quot;&gt;&quot;%ebx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;             &lt;span class=&quot;s&quot;&gt;&quot;%ecx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;%edx&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    &amp;lt;span class=&quot;n&quot;&amp;gt;regs&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;[&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;mi&quot;&amp;gt;0&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;]&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;eax&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;;&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;n&quot;&amp;gt;regs&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;[&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;mi&quot;&amp;gt;1&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;]&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;ebx&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;;&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;n&quot;&amp;gt;regs&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;[&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;mi&quot;&amp;gt;2&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;]&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;ecx&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;;&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;n&quot;&amp;gt;regs&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;[&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;mi&quot;&amp;gt;3&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;]&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;edx&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;;&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;For additional information, I found &lt;a href=&quot;http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well&quot;&gt;Sam Hocovar's
post&lt;/a&gt;
to be quite informative.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Find command in $PATH</title>
            <link href="http://tuxion.com/2010/04/19/find-cmd-in-path.html"/>
            <updated>2010-04-19T00:00:00-04:00</updated>
            <id>http://tuxion.com/2010/04/19/find-cmd-in-path</id>
            <content type="html">&lt;p&gt;I make calls to external commands from Python quite often. Sometimes it is
desirable to know if a command is available on the running system before making
a call to &lt;code&gt;subprocess.call()&lt;/code&gt;. Here's the code I came up with for doing that:&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;os&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;find_in_path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;PATH&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pathsep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;full_cmd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_cmd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;X_OK&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_cmd&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;If there's a better way to do this, or even a builtin python way, don't
hesitate to mention it.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Periodic timers in PyGTK</title>
            <link href="http://tuxion.com/2010/04/16/periodic-timers-in-pygtk.html"/>
            <updated>2010-04-16T00:00:00-04:00</updated>
            <id>http://tuxion.com/2010/04/16/periodic-timers-in-pygtk</id>
            <content type="html">&lt;p&gt;I've been writing a ton of &lt;a href=&quot;http://www.python.org&quot;&gt;Python&lt;/a&gt; code lately and I'm
absolutely loving it. As a C programmer for the better part of the last 15
years, I find the syntax and ease of expression to be refreshing and fun.&lt;/p&gt;

&lt;p&gt;I've recently been tasked with writing a GUI interface to an existing product
we have at &lt;a href=&quot;http://www.miserware.com&quot;&gt;MiserWare&lt;/a&gt; called
&lt;a href=&quot;http://grano.la&quot;&gt;Granola&lt;/a&gt; -- a free (as in beer) version of our enterprise
power management solution.&lt;/p&gt;

&lt;p&gt;I found myself needing a periodic timer to update the window with new
statistics coming in from the daemon. You can do this in regular python, but
PyGTK, specifically &lt;code&gt;gobject&lt;/code&gt;, makes it very easy. Here's an example that draws
a simple window with a label displaying the current counter.&lt;/p&gt;

&lt;p&gt;&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c&quot;&gt;#!/usr/bin/env python&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;gtk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;gobject&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;PerodicTimer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;&lt;strong&gt;init&lt;/strong&gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    &amp;lt;span class=&quot;c&quot;&amp;gt;# create a simple window with a label&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;window&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;gtk&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;Window&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;()&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;window&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;connect&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;s&quot;&amp;gt;'destroy'&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;k&quot;&amp;gt;lambda&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;wid&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;:&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;gtk&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;main_quit&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;())&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;window&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;connect&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;s&quot;&amp;gt;'delete_event'&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;k&quot;&amp;gt;lambda&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;a1&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;,&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;a2&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;:&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;gtk&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;main_quit&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;())&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;n&quot;&amp;gt;vbox&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;gtk&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;VBox&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;()&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;window&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;add&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;vbox&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;)&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;label&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;n&quot;&amp;gt;gtk&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;Label&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;s&quot;&amp;gt;'Periodic Timer'&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;)&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;n&quot;&amp;gt;vbox&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;pack_start&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;label&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;)&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;window&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;show_all&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;()&amp;lt;/span&amp;gt;

    &amp;lt;span class=&quot;c&quot;&amp;gt;# register a periodic timer&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;counter&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;mi&quot;&amp;gt;0&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;n&quot;&amp;gt;gobject&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;timeout_add_seconds&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;timeout&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;,&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;callback&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;)&amp;lt;/span&amp;gt;

&amp;lt;span class=&quot;k&quot;&amp;gt;def&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;nf&quot;&amp;gt;callback&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;):&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;label&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;set_text&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;s&quot;&amp;gt;'Counter: '&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;+&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;nb&quot;&amp;gt;str&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;(&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;counter&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;p&quot;&amp;gt;))&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;bp&quot;&amp;gt;self&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;o&quot;&amp;gt;.&amp;lt;/span&amp;gt;&amp;lt;span class=&quot;n&quot;&amp;gt;counter&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;o&quot;&amp;gt;+=&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;mi&quot;&amp;gt;1&amp;lt;/span&amp;gt;
    &amp;lt;span class=&quot;k&quot;&amp;gt;return&amp;lt;/span&amp;gt; &amp;lt;span class=&quot;bp&quot;&amp;gt;True&amp;lt;/span&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;&lt;strong&gt;name&lt;/strong&gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'&lt;strong&gt;main&lt;/strong&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;periodic_timer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PerodicTimer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;gtk&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/p&gt;

&lt;p&gt;The bulk of the code is just setting up a gtk window, the timer code is only 5
lines or so. As long as &lt;code&gt;callback()&lt;/code&gt; returns &lt;code&gt;True&lt;/code&gt;, the timer gets
re-registered for the original timeout value (1 second in this example). One
caveat I found, &lt;code&gt;gobject.timeout_add_seconds()&lt;/code&gt; seems to depend on the GTK main
loop, so you cannot use it from a regular non-GTK python application.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Byobu Rackspace Cost Plugin</title>
            <link href="http://tuxion.com/2010/01/23/byobu-rackspace-cost-plugin.html"/>
            <updated>2010-01-23T00:00:00-05:00</updated>
            <id>http://tuxion.com/2010/01/23/byobu-rackspace-cost-plugin</id>
            <content type="html">&lt;p&gt;If you haven't heard of &lt;a href=&quot;https://launchpad.net/byobu&quot;&gt;Byobu&lt;/a&gt; you're missing
out. It's an enhancement to GNU screen that, among many cool features, allows
users to define their own plugins and have them displayed in the statusbar
along the bottom of the terminal.&lt;/p&gt;

&lt;p&gt;The default installation comes with a plugin that displays the approximate
Amazon EC2 cost of the running instance. I wanted a plugin that worked for
Rackspace servers, so I modified it and implemented the Rackspace Cloudserver
pricing model to create
&lt;a href=&quot;http://github.com/jbernard/byobu-rcs-cost&quot;&gt;byobu-rcs-cost&lt;/a&gt;. Documentation is
in the README, it's pretty straightforward to install and use.&lt;/p&gt;

&lt;p&gt;Now I can quickly see the estimated cost of each server I'm logged into, pretty
cool.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; This plugin was merged into the official byobu release as of
version 2.73. See the &lt;a href=&quot;https://launchpad.net/byobu&quot;&gt;byobu project page&lt;/a&gt; for
more details.&lt;/p&gt;
</content>
        </entry>
    
        <entry>
            <title>Ubuntu Resource Management</title>
            <link href="http://tuxion.com/2009/10/13/ubuntu-resource-managment-simple-example.html"/>
            <updated>2009-10-13T00:00:00-04:00</updated>
            <id>http://tuxion.com/2009/10/13/ubuntu-resource-managment-simple-example</id>
            <content type="html">&lt;p&gt;I recently wanted to limit CPU usage on my Ubuntu Karmic workstation. Since
&lt;a href=&quot;https://launchpad.net/ubuntu/+source/libcgroup&quot;&gt;libcgroup&lt;/a&gt; is included in the
upcoming Karmic release, setting up cgroups on an Ubuntu server has never been
easier.&lt;/p&gt;

&lt;h3&gt;The Goal&lt;/h3&gt;

&lt;p&gt;My needs were as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My machine is dedicated to running an Apache Web Server and I would like for
it to have priority on the CPU whenever it's needed.&lt;/li&gt;
&lt;li&gt;I have an occasional user on my system that chews up CPU like it's going out
of style and slows down my web server. In this example, we'll call this user
&lt;em&gt;kirkland&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The goal is to only allow kirkland CPU cycles when no other process is
requesting them. Similar to a &lt;em&gt;sponge&lt;/em&gt;, kirkland will be throttled to 0 if my
apache daemon is really busy.&lt;/p&gt;

&lt;h3&gt;Getting There&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Install libcgroup:&lt;/li&gt;
&lt;/ol&gt;


&lt;pre class=&quot;terminal&quot;&gt;&lt;code&gt;$ sudo aptitude install libcgroup cgroup-bin
&lt;/code&gt;&lt;/pre&gt;


&lt;ol&gt;
&lt;li&gt;Edit /etc/cgconfig.conf, define a sponge group:&lt;/li&gt;
&lt;/ol&gt;


&lt;pre&gt;&lt;code&gt;group sponge {
        perm {
            task {
                uid = kirkland;
                gid = kirkland;
            }
            admin {
                uid = root;
                gid = root;
            }
        }
        cpu {
            cpu.shares = 1;
        }
    }
    mount {
        cpu = /mnt/cgroups/cpu;
        cpuacct = /mnt/cgroups/cpuacct;
}&lt;/code&gt;&lt;/pre&gt;


&lt;ol&gt;
&lt;li&gt;Edit /etc/cgrules.conf, assign kirkland to the sponge group:&lt;/li&gt;
&lt;/ol&gt;


&lt;pre&gt;&lt;code&gt;kirkland         cpu             sponge/&lt;br&gt;*                *               sysdefault/&lt;/code&gt;&lt;/pre&gt;


&lt;ol&gt;
&lt;li&gt;Restart cgconfig and cgred services:&lt;/li&gt;
&lt;/ol&gt;


&lt;pre class=&quot;terminal&quot;&gt;&lt;code&gt;$ sudo service cgconfig restart
$ sudo service cgred restart
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Processes created by kirkland should now automatically get moved into the
sponge cgroup and will only recieve CPU cycles when no other processes are in
need.&lt;/p&gt;

&lt;p&gt;For more information about libgroup, you can visit the &lt;a href=&quot;http://libcg.sourceforge.net/&quot;&gt;libcgroup project
page&lt;/a&gt;. And for cgroups in general see the
&lt;a href=&quot;http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=tree;f=Documentation/cgroups&quot;&gt;current kernel
documentation&lt;/a&gt;.&lt;/p&gt;
</content>
        </entry>
    

</feed>
