<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>Advogato blog for aleix</title>
    <link>http://www.advogato.org/person/aleix/</link>
    <description>Advogato blog for aleix</description>
    <language>en-us</language>
    <generator>mod_virgule</generator>
    <pubDate>Wed, 22 May 2013 05:28:13 GMT</pubDate>
    <item>
      <pubDate>Tue, 30 Apr 2013 23:11:36 GMT</pubDate>
      <title>Tweak your Guile REPL</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=71</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2013/04/30/tweak-your-guile-repl</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;If you are new to &lt;a href="http://www.gnu.org/software/guile/" &gt;Guile&lt;/a&gt; and start the REPL right away you will find yourself with no history, no completions, no colors and even the cursor keys not working as expected.&lt;/p&gt;
    &lt;p&gt;Fortunately, all these problems can be solved by loading a couple of modules.&lt;/p&gt;
    &lt;p&gt;The first one is to enable &lt;a href="http://www.gnu.org/software/guile/manual/html_node/Readline-Support.html#Readline-Support" &gt;readline&lt;/a&gt; support. This will enable command history, completions (pressing TAB), cursors will work properly, you will have parenthesis matching, Emacs key bindings support and more.&lt;/p&gt;
    &lt;p&gt;Simply put this in ~/.guile:&lt;/p&gt;
    &lt;pre&gt;
(use-modules (ice-9 readline))
(activate-readline)
&lt;/pre&gt;
    &lt;p&gt;To colorize the REPL there is also an awesome new module, &lt;a href="https://github.com/NalaGinrut/nala-repl" &gt;nala-repl&lt;/a&gt;. This module doesn't come with Guile yet, so you have to clone the repository and install it yourself:&lt;/p&gt;
    &lt;pre&gt;
$ git clone git://github.com/NalaGinrut/nala-repl.git
$ cd nala-repl
$ sudo make install
&lt;/pre&gt;
    &lt;p&gt;And, as before, add the following lines to your ~/.guile:&lt;/p&gt;
    &lt;pre&gt;
(use-modules (nala colorized))
(activate-colorized)
&lt;/pre&gt;
    &lt;p&gt;&lt;em&gt;nala-repl&lt;/em&gt; provides some more nice modules, make sure to read the README file.&lt;/p&gt;
    &lt;p&gt;Now, go and enjoy the Guile REPL!&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Thu, 25 Apr 2013 00:11:15 GMT</pubDate>
      <title>32-bit and 64-bit return values in OS X</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=70</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2013/04/25/32-bit-and-64-bit-return-values-in-os-x</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;I've spent a couple of days with a silly compiler problem. I have to admit that it was my fault but, at least, I learned something in the process. To make a long story short: &lt;em&gt;do not forget to include header files and enable all warnings (-Wall)&lt;/em&gt;.&lt;/p&gt;
    &lt;p&gt;In C, you can use a function without including its header file. Then, depending on how you set the compiler flags, it might not complain as long as it can find the function at linking time.&lt;/p&gt;
    &lt;p&gt;Imagine you have this function (defined in &lt;em&gt;foo.h&lt;/em&gt; and implemented in &lt;em&gt;foo.c&lt;/em&gt;) :&lt;/p&gt;
    &lt;pre&gt;
unsigned long foo_add (void);
&lt;/pre&gt;
    &lt;p&gt;and you use it in another module &lt;em&gt;bar.c&lt;/em&gt; without including the &lt;em&gt;foo.h&lt;/em&gt; header:&lt;/p&gt;
    &lt;pre&gt;
//#include "foo.h"

unsigned long bar_add (void)
{
  return foo_add () + foo_add ();
}
&lt;/pre&gt;
    &lt;p&gt;Compile with: gcc -c -O2  bar.c  (we just missed -Wall)&lt;/p&gt;
    &lt;p&gt;If we disassemble the code of &lt;em&gt;bar.o&lt;/em&gt; we get:&lt;/p&gt;
    &lt;pre&gt;
$ otool -tV bar.o
bar.o:
(__TEXT,__text) section
_bar_add:
...
000000000000000b callq _foo_add
0000000000000010 movl  %eax, %ebx
...
0000000000000024 ret
&lt;/pre&gt;
    &lt;p&gt;Now, let's try to include the header &lt;em&gt;foo.h&lt;/em&gt; and disassemble again:&lt;/p&gt;
    &lt;pre&gt;
$ otool -tV bar.o
bar.o:
(__TEXT,__text) section
_bar_add:
...
0000000000000009 callq _foo_add
000000000000000e movq  %rax, %rbx
...
000000000000001f ret
&lt;/pre&gt;
    &lt;p&gt;Note how the compiler uses two different instructions: &lt;em&gt;movl&lt;/em&gt; (32-bit) in the first case, when it really doesn't know anything about the &lt;em&gt;foo_add&lt;/em&gt; function, and &lt;em&gt;movq&lt;/em&gt; (64-bit) when it knows that &lt;em&gt;foo_add&lt;/em&gt; returns a 64-bit value.&lt;/p&gt;
    &lt;p&gt;This can lead to unexpected behavior as I have found in the code I was working on. And actually, I have only found this in OS X.&lt;/p&gt;
    &lt;p&gt;So, please &lt;em&gt;do not forget to include header files and enable -Wall&lt;/em&gt;. It will save you from some headaches.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Wed, 24 Apr 2013 23:10:44 GMT</pubDate>
      <title>32-bit and 64-bit return values in OS X</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=69</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2013/04/24/32-bit-and-64-bit-return-values-in-os-x</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;I've spent a couple of days with a dummy compiler problem. I have to admit that it was my fault but, at least, I learned something in the process. To make a long story short: &lt;em&gt;do not forget to include header files and enable all warnings (-Wall)&lt;/em&gt;.&lt;/p&gt;
    &lt;p&gt;In C, you can use a function without including its header file. Then, depending on how you set the compilers flags, it might not complain as long as it can find the function at linking time.&lt;/p&gt;
    &lt;p&gt;Imagine you have this function (defined in &lt;em&gt;foo.h&lt;/em&gt; and implemented in &lt;em&gt;foo.c&lt;/em&gt;) :&lt;/p&gt;
    &lt;pre&gt;
uint64_t foo_add (void);
&lt;/pre&gt;
    &lt;p&gt;and you use it in a program &lt;em&gt;bar.c&lt;/em&gt; without including the &lt;em&gt;foo.h&lt;/em&gt; header:&lt;/p&gt;
    &lt;pre&gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

int
main (int argc, char *argv[])
{
  printf ("%d\n", foo_add ());

  return 0;
}
&lt;/pre&gt;
    &lt;p&gt;(yes, &lt;em&gt;printf&lt;/em&gt; will complain in this case because of type mismatches, just imagine &lt;em&gt;printf&lt;/em&gt; is something else).&lt;/p&gt;
    &lt;p&gt;If we disassemble the code of our program we get:&lt;/p&gt;
    &lt;pre&gt;
$ otool -tV bar
bar.o:
(__TEXT,__text) section
_main:
...
0000000000000006 callq  _foo_add
...
0000000000000012 movl   %eax, %esi
...
000000000000001e ret
&lt;/pre&gt;
    &lt;p&gt;Now, let's try to include the header &lt;em&gt;foo.h&lt;/em&gt; and disassemble again:&lt;/p&gt;
    &lt;pre&gt;
$ otool -tV bar
bar.o:
(__TEXT,__text) section
_main:
...
0000000000000004 callq  _foo_add
...
0000000000000010 movq  %rax, %rsi
...
000000000000001d ret
&lt;/pre&gt;
    &lt;p&gt;Note how the compiler uses two different instructions: &lt;em&gt;movl&lt;/em&gt; (32-bit) in the first case, when it really doesn't know anything about the &lt;em&gt;foo_add&lt;/em&gt; function, and &lt;em&gt;movq&lt;/em&gt; (64-bit) when it knows that &lt;em&gt;foo_add&lt;/em&gt; returns a 64-bit value.&lt;/p&gt;
    &lt;p&gt;This can lead to unexpected behavior as I have found in the code I was working on. And actually, I have only found this in OS X.&lt;/p&gt;
    &lt;p&gt;So, please &lt;em&gt;do not forget to include header files and enable -Wall&lt;/em&gt;. It will save you from some headaches.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Sat, 13 Apr 2013 15:11:26 GMT</pubDate>
      <title>add1, sub1 and + recursive process</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=68</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2013/04/13/add1-sub1-and-recursive-process</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;In The Little Schemer you are asked to write the function + using the functions &lt;em&gt;zero?&lt;/em&gt;, &lt;em&gt;add1&lt;/em&gt; and &lt;em&gt;sub1&lt;/em&gt;, such as the result of &lt;em&gt;(+ 46 12)&lt;/em&gt; is &lt;em&gt;58&lt;/em&gt;.&lt;/p&gt;
    &lt;pre&gt;
(define add1
  (lambda (n) (+ n 1)))

(define sub1
  (lambda (n) (- n 1)))
&lt;/pre&gt;
    &lt;p&gt;The solution given is:&lt;/p&gt;
    &lt;pre&gt;
(define o+
  (lambda (n m)
    (cond
      ((zero? m) n)
      (else (add1 (o+ n (sub1 m)))))))
&lt;/pre&gt;
    &lt;p&gt;which is correct but has a little problem.&lt;/p&gt;
    &lt;p&gt;If you are like me (hopefully not), you might have read twenty times the first chapters of SICP (and haven't gone any further). Remember about recursive and iterative processes and recursive procedures? In our &lt;em&gt;o+&lt;/em&gt; case we have a &lt;em&gt;recursive procedure&lt;/em&gt; that generates a &lt;em&gt;recursive process&lt;/em&gt;, as the process generates a chain of deferred &lt;em&gt;add1&lt;/em&gt; operations.&lt;/p&gt;
    &lt;p&gt;With a recursive process we can easily blow our stack:&lt;/p&gt;
    &lt;pre&gt;
scheme@(guile-user)&amp;gt; (o+ 10 100000)
While executing meta-command:
ERROR: Throw to key `vm-error' with args `(vm-run "VM: Stack overflow" ())'.
&lt;/pre&gt;
    &lt;p&gt;This is because this will generate:&lt;/p&gt;
    &lt;pre&gt;
(add1 (add1 (add1 (add1 ...... n))))
&lt;/pre&gt;
    &lt;p&gt;with as many &lt;em&gt;add1&lt;/em&gt; as &lt;em&gt;m&lt;/em&gt;.&lt;/p&gt;
    &lt;p&gt;So, how to improve this? With a recursive procedure that generates an &lt;em&gt;iterative process&lt;/em&gt;:&lt;/p&gt;
    &lt;pre&gt;
(define o+
  (lambda (n m)
    (cond
      ((zero? m) n)
      (else (o+ (add1 n) (sub1 m))))))
&lt;/pre&gt;
    &lt;p&gt;which will generate:&lt;/p&gt;
    &lt;pre&gt;
(o+ 11 99999)
(o+ 12 99998)
...
(o+ 100010 0)
&lt;/pre&gt;
    &lt;p&gt;and doesn't overflow the stack. &lt;/p&gt;
    &lt;p&gt;scheme@(guile-user)&amp;gt; (o+ 10 100000)&lt;br/&gt;$1 = 100010&lt;/p&gt;
    &lt;p&gt;Yes, this is a &lt;a href="http://en.wikipedia.org/wiki/Tail_call" &gt;tail-recursive&lt;/a&gt; function.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Wed, 10 Apr 2013 07:13:54 GMT</pubDate>
      <title>The Law of Car</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=67</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2013/04/10/the-law-of-car</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;In The Little Schemer, The Law of Car is defined as:&lt;/p&gt;
    &lt;blockquote&gt;
      &lt;p&gt;The primitive car is defined only for non-empty lists.&lt;/p&gt;
    &lt;/blockquote&gt;
    &lt;p&gt;In the implementation given for &lt;em&gt;(firsts l)&lt;/em&gt;, it seems to me that the law is broken:&lt;/p&gt;
    &lt;pre&gt;
(define firsts
  (lambda (l)
    (cond
      ((null? l) '())
      (else (cons (car (car l))
                  (firsts (cdr l)))))))
&lt;/pre&gt;
    &lt;p&gt;As &lt;em&gt;(firsts '())&lt;/em&gt; is &lt;em&gt;'()&lt;/em&gt;. So, this would actually fail (in &lt;a href="http://www.gnu.org/software/guile/" &gt;guile&lt;/a&gt;):&lt;/p&gt;
    &lt;pre&gt;
$ (firsts '((a b) () (e f)))
In procedure firsts:
In procedure car: Wrong type argument in position 1 (expecting pair): ()
&lt;/pre&gt;
    &lt;p&gt;I think a correct implementation would be:&lt;/p&gt;
    &lt;pre&gt;
(define (firsts l)
  (cond
   ((null? l) '())
   (else (cond
          ((null? (car l)) (firsts (cdr l)))
          (else
           (cons (car (car l))
                 (firsts (cdr l))))))))
&lt;/pre&gt;
    &lt;p&gt;in which we take care of the non-empty list before getting the first typical element &lt;em&gt;(car (car l))&lt;/em&gt;. This would result in:&lt;/p&gt;
    &lt;pre&gt;
$ (firsts '((a b) () (e f)))
(a e)
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Tue, 8 Jan 2013 16:10:07 GMT</pubDate>
      <title>Install Emacs packages from command line</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=66</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2013/01/08/install-emacs-packages-from-command-line</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;Lately, I have found myself playing with packages and my .emacs too much. Sometimes I had to comment the use of a package (e.g. smex) because it was not installed.&lt;/p&gt;
    &lt;p&gt;So, at the end, I wrote this basic elisp to install a package from the command line.&lt;/p&gt;
    &lt;pre&gt;
$ emacs --batch --expr "(define pkg-to-install 'smex)" -l emacs-pkg-install.el
&lt;/pre&gt;
    &lt;p&gt;The &lt;a href="http://www.advogato.org/aleix/files/scripts/emacs-pkg-install.el" &gt;elisp script&lt;/a&gt; looks like this:&lt;/p&gt;
    &lt;pre&gt;
;;
;; Install package from command line. Example:
;;
;;   $ emacs --batch --expr "(define pkg-to-install 'smex)" -l emacs-pkg-install.el
;;

(require 'package)

(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)

(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)

;; Fix HTTP1/1.1 problems
(setq url-http-attempt-keepalives nil)

(package-refresh-contents)

(package-install pkg-to-install)
&lt;/pre&gt;
    &lt;p&gt;For convenience, you can wrap it in a &lt;a href="http://www.advogato.org/aleix/files/scripts/emacs-pkg-install.sh" &gt;shell script&lt;/a&gt; and simply type:&lt;/p&gt;
    &lt;pre&gt;
$ ./emacs-pkg-install.sh smex
&lt;/pre&gt;
    &lt;p&gt;The shell script:&lt;/p&gt;
    &lt;pre&gt;
#!/bin/sh

if [ $# -ne 1 ]
then
  echo "Usage: `basename $0` &amp;lt;package&amp;gt;"
  exit 1
fi

emacs --batch --eval "(defconst pkg-to-install '$1)" -l emacs-pkg-install.el
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Tue, 8 Jan 2013 11:18:53 GMT</pubDate>
      <title>Install Emacs packages from command line</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=65</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2013/01/08/install-emacs-packages-from-command-line</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;Lately, I have found myself playing with packages and my .emacs too much. Sometimes I had to comment the use of a package (e.g. smex) because it was not installed.&lt;/p&gt;
    &lt;p&gt;So, at the end, I wrote this basic Emacs lisp to install a package from the command line. Just type:&lt;/p&gt;
    &lt;pre&gt;
$ emacs --batch --expr "(define pkg-to-install 'smex)" -l emacs-pkg-install.el
&lt;/pre&gt;
    &lt;p&gt;The script looks like this:&lt;/p&gt;
    &lt;pre&gt;
;;
;; Install package from command line. Example:
;;
;;   $ emacs --batch --expr "(define pkg-to-install 'smex)" -l emacs-pkg-install.el
;;

(require 'package)

(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)

(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)

;; Fix HTTP1/1.1 problems
(setq url-http-attempt-keepalives nil)

(package-refresh-contents)

(package-install pkg-to-install)
&lt;/pre&gt;
    &lt;p&gt;For convenience, you can wrap it in a shell script and simply type:&lt;/p&gt;
    &lt;pre&gt;
$ ./emacs-pkg-install.sh smex
&lt;/pre&gt;
    &lt;p&gt;The shell script:&lt;/p&gt;
    &lt;pre&gt;
#!/bin/sh

if [ $# -ne 1 ]
then
  echo "Usage: `basename $0` &amp;lt;package&amp;gt;"
  exit 1
fi

emacs --batch --eval "(defconst pkg-to-install '$1)" -l emacs-pkg-install.el
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Thu, 15 Nov 2012 01:09:31 GMT</pubDate>
      <title>git-cherry-base</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=64</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2012/11/15/git-cherry-base</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;If you use &lt;a href="http://git-scm.com/" &gt;git&lt;/a&gt;, you might find yourself wanting to merge a huge list of commits into a branch, but you might not want all of them. &lt;a href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html" &gt;git-rebase&lt;/a&gt; already helps with this task but it becomes less convenient when you have lots of commits as you may not remember all of them and also because it doesn't show you the contents of each commit&lt;/p&gt;
    &lt;p&gt;&lt;a href="http://hacks-galore.org/aleix/files/scripts/git-cherry-base" &gt;git-cherry-base&lt;/a&gt; is an interactive script (written in &lt;a href="http://www.gnu.org/software/guile/" &gt;Guile&lt;/a&gt;) that lets you choose which commits you'd like to merge and even which parts of the commit you want. Given a list of revisions (obtained from &lt;a href="http://www.kernel.org/pub/software/scm/git/docs/git-rev-list.html" &gt;git-rev-list&lt;/a&gt;) it will show the contents for each commit and will let you choose if you want to merge the commit, skip it or merge only parts of it.&lt;/p&gt;
    &lt;pre&gt;
Usage: git-cherry-base rev-file
&lt;/pre&gt;
    &lt;p&gt;I wrote it some months ago as I couldn't find any other command line tool to do this and, well, it was just a good excuse to hack something in Scheme.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Mon, 15 Aug 2011 15:07:12 GMT</pubDate>
      <title>Packing and unpacking bit structures in Python</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=63</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2011/08/15/packing-and-unpacking-bit-structures-in-python</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;Last week, I released the first version of the &lt;a href="http://www.nongnu.org/bitpacket" &gt;BitPacket&lt;/a&gt; Python module which allows you to pack and unpack data like the &lt;a href="http://docs.python.org/lib/module-struct.html" &gt;struct&lt;/a&gt; and &lt;a href="http://docs.python.org/lib/module-array.html" &gt;array&lt;/a&gt; modules, but in an object-oriented way. At work I needed an easy way to create network packets and at that time I did not know the existence of the &lt;i&gt;struct&lt;/i&gt; and &lt;i&gt;array&lt;/i&gt; modules, so I googled a bit and I found out the &lt;a href="http://cobweb.ecn.purdue.edu/~kak/dist/BitVector-1.3.html" &gt;BitVector&lt;/a&gt; class for a memory-efficient packed representation of bit arrays, which I decided to use for my purpose.&lt;/p&gt;
    &lt;p&gt;I implemented three classes, &lt;i&gt;BitField&lt;/i&gt;, &lt;i&gt;BitStructure&lt;/i&gt; and &lt;i&gt;BitVariableStructure&lt;/i&gt; (the lastest two are derived from &lt;i&gt;BitField&lt;/i&gt;). A network packet would be represented by the &lt;i&gt;BitStructure&lt;/i&gt; class, which at creation does not contain any field, and the idea is that any &lt;i&gt;BitField&lt;/i&gt; subclass might be added to it.&lt;/p&gt;
    &lt;p&gt;I'll will show you the most basic example. Suppose, you need a simple network packet like the one below:&lt;/p&gt;
    &lt;pre&gt;
+---------------+-------------------+
|  id (1 byte)  |  address (4 byte) |
+---------------+-------------------+
&lt;/pre&gt;
    &lt;p&gt;You could easily create a network packet using &lt;i&gt;BitStructure&lt;/i&gt;, like this:&lt;/p&gt;
    &lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; bs = BitStructure('mypacket')
&amp;gt;&amp;gt;&amp;gt; bs.append(BitField('id', BYTE_SIZE, 0x54))
&amp;gt;&amp;gt;&amp;gt; bs.append(BitField('address', INTEGER_SIZE, 0x10203040))
&lt;/pre&gt;
    &lt;p&gt;and print its contents:&lt;/p&gt;
    &lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; print bs
&amp;gt;&amp;gt;&amp;gt; (mypacket =
&amp;gt;&amp;gt;&amp;gt;   (id = 0x54)
&amp;gt;&amp;gt;&amp;gt;   (address = 0x10203040))
&lt;/pre&gt;
    &lt;p&gt;In order to unpack an incoming packet, we could use the variable created above or a new one without default values:&lt;/p&gt;
    &lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; bs = BitStructure('mypacket')
&amp;gt;&amp;gt;&amp;gt; bs.append(BitField('id', BYTE_SIZE))
&amp;gt;&amp;gt;&amp;gt; bs.append(BitField('address', INTEGER_SIZE))
&lt;/pre&gt;
    &lt;p&gt;In order to unpack an incoming array of bytes, we would do the following:&lt;/p&gt;
    &lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; data = array.array('B', [0x38, 0x87, 0x34, 0x21, 0x40])
&amp;gt;&amp;gt;&amp;gt; bs.set_stream(data)
&lt;/pre&gt;
    &lt;p&gt;We can then access to the packet fields by their name:&lt;/p&gt;
    &lt;pre&gt;
&amp;gt;&amp;gt;&amp;gt; print '0x%X' % bs['id']
0x38
&amp;gt;&amp;gt;&amp;gt; print '0x%X' % bs['address']
0x87342140
&lt;/pre&gt;
    &lt;p&gt;There are a lot more possibilities to pack and unpack bit field structures by using &lt;i&gt;BitStructure&lt;/i&gt; and &lt;i&gt;BitVariableStructure&lt;/i&gt;. You can see all of them in the module's online &lt;a href="http://www.nongnu.org/bitpacket/doc/api/index.html" &gt;documentation&lt;/a&gt;.&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
    <item>
      <pubDate>Tue, 28 Jun 2011 14:06:30 GMT</pubDate>
      <title>Emacs 23.3 for RHEL 6</title>
      <link>http://www.advogato.org/person/aleix/diary.html?start=62</link>
      <guid>http://hacks-galore.org/aleix/blog/archives/2011/06/28/emacs-23-3-for-rhel-6</guid>
      <description>&lt;div&gt;
  &lt;div&gt;
    &lt;p&gt;Emacs version in RHEL 6.1 is very outdated, 23.1 (which was released on July 2009). I needed a newer version to run &lt;a href="http://www.nongnu.org/geiser/" &gt;Geiser&lt;/a&gt; at work, so after searching for the package in the typical places (&lt;a href="http://rpmfind.net" &gt;rpmfind.net&lt;/a&gt; and &lt;a href="http://rpm.pbone.net/" &gt;rpm.pbone.net&lt;/a&gt;) and Google I decided to build my own one. For it, I just followed these &lt;a href="http://wiki.centos.org/HowTos/RebuildSRPM" &gt;instructions&lt;/a&gt; on how to build Source RPM packages and did some minor updates on the RPM spec file. &lt;/p&gt;
    &lt;p&gt;So, simply download &lt;a href="http://hacks-galore.org/aleix/files/emacs-23.3-1.el6.src.rpm" &gt;emacs-23.3-1.el6.src.rpm&lt;/a&gt; and follow these instructions:&lt;/p&gt;
    &lt;p&gt;This will only create an rpmbuild directory in your home:&lt;/p&gt;
    &lt;pre&gt;
$ rpm -i emacs-23.3-1.el6.src.rpm
&lt;/pre&gt;
    &lt;p&gt;Install rpm-build if you don't have it, and build the Emacs RPMs:&lt;/p&gt;
    &lt;pre&gt;
$ cd $HOME/rpmbuild/SPECS
$ rpmbuild -ba emacs.spec
&lt;/pre&gt;
    &lt;p&gt;Finally, upgrade your old installed Emacs and happy hacking!&lt;/p&gt;
    &lt;pre&gt;
$ cd $HOME/rpmbuild/RPMS
$ sudo rpm -U emacs-23.3-1.el6.x86_64.rpm emacs-common-23.3-1.el6.x86_64.rpm
&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;</description>
    </item>
  </channel>
</rss>
