Older blog entries for aleix (starting at number 63)

Packing and unpacking bit structures in Python

Last week, I released the first version of the BitPacket Python module which allows you to pack and unpack data like the struct and array 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 struct and array modules, so I googled a bit and I found out the BitVector class for a memory-efficient packed representation of bit arrays, which I decided to use for my purpose.

I implemented three classes, BitField, BitStructure and BitVariableStructure (the lastest two are derived from BitField). A network packet would be represented by the BitStructure class, which at creation does not contain any field, and the idea is that any BitField subclass might be added to it.

I'll will show you the most basic example. Suppose, you need a simple network packet like the one below:

+---------------+-------------------+
|  id (1 byte)  |  address (4 byte) |
+---------------+-------------------+

You could easily create a network packet using BitStructure, like this:

>>> bs = BitStructure('mypacket')
>>> bs.append(BitField('id', BYTE_SIZE, 0x54))
>>> bs.append(BitField('address', INTEGER_SIZE, 0x10203040))

and print its contents:

>>> print bs
>>> (mypacket =
>>>   (id = 0x54)
>>>   (address = 0x10203040))

In order to unpack an incoming packet, we could use the variable created above or a new one without default values:

>>> bs = BitStructure('mypacket')
>>> bs.append(BitField('id', BYTE_SIZE))
>>> bs.append(BitField('address', INTEGER_SIZE))

In order to unpack an incoming array of bytes, we would do the following:

>>> data = array.array('B', [0x38, 0x87, 0x34, 0x21, 0x40])
>>> bs.set_stream(data)

We can then access to the packet fields by their name:

>>> print '0x%X' % bs['id']
0x38
>>> print '0x%X' % bs['address']
0x87342140

There are a lot more possibilities to pack and unpack bit field structures by using BitStructure and BitVariableStructure. You can see all of them in the module's online documentation.

Syndicated 2011-08-15 14:40:39 from aleix's blog

Emacs 23.3 for RHEL 6

Emacs version in RHEL 6.1 is very outdated, 23.1 (which was released on July 2009). I needed a newer version to run Geiser at work, so after searching for the package in the typical places (rpmfind.net and rpm.pbone.net) and Google I decided to build my own one. For it, I just followed these instructions on how to build Source RPM packages and did some minor updates on the RPM spec file.

So, simply download emacs-23.3-1.el6.src.rpm and follow these instructions:

This will only create an rpmbuild directory in your home:

$ rpm -i emacs-23.3-1.el6.src.rpm

Install rpm-build if you don't have it, and build the Emacs RPMs:

$ cd $HOME/rpmbuild/SPECS
$ rpmbuild -ba emacs.spec

Finally, upgrade your old installed Emacs and happy hacking!

$ cd $HOME/rpmbuild/RPMS
$ sudo rpm -U emacs-23.3-1.el6.x86_64.rpm emacs-common-23.3-1.el6.x86_64.rpm

Syndicated 2011-06-28 13:12:12 from aleix's blog

more tekuti hacks

I have had less time lately, but I still found some minutes to hack on tekuti. The most important new feature is performance. tekuti is now one or two order of magnitudes faster than before. No more delays when accessing posts or listing tags or archives posts. Basically, accesses to git have been reduced to the minimumn. So, these are the new features since last post:

  • Fixes: search works again.

  • Performance: reduction of git accesses (and adding Look-Up-Tables) has improved speed dramatically.

  • New widgets: blank and page-rank.

  • Page navigation: the new links at the bottom (go to the end of the page) allow navigation through all blog history.

  • Cosmetics: post lists (in tags or archives) show the post date besides the title...

You can check out all these new features from gitorious:

git clone git://gitorious.org/~aleix/tekuti/acf-tekuti.git

Happy hacking!

Syndicated 2011-03-01 15:58:43 from aleix's blog

tekuti hacks

Lately, I've been hacking new features for tekuti, the blogging software that's running this site. tekuti is written in Scheme , so I had no more excuses to start hacking on it.

Blah, blah, blah... but what have you done? Nothing really impressive, indeed, but quite useful for my needs:

  • Support for deleting posts. As tekuti is based on git, it's easy to recover them for free. And you don't need to spell any git command, tekuti admin interface can help you here.

  • Support for deleting post comments. This is useful if undesired spam gets in your site.

  • Support for custom user templates. Before, there was only one template. Now, it is possible to add multiple templates and choose your desired one from the configuration file (via the *template-module* variable).

  • Configure widgets on the sidebar. You can now configure the widgets you want to appear in your blog sidebar. Mine, looks like this:

    (set! *main-sidebar-widgets* `(subscribe search tag-list))
    (set! *post-sidebar-widgets* `(subscribe related))
    

    Available widgets are: subscribe, search, related, tag-cloud, tag-list.

  • Support Movable Type API. This means it is now possible to use your favorite blog editor and post or edit your tekuti articles. You need to configure tekuti as a Movable Type blog. The XMLRPC endpoint is http://yoursite.com/path-to-blog/xmlrpc.In fact, some MetaWeblog and Blogger methods have been also implemented. This is the list of supported methods:

    • metaWeblog.newPost

    • metaWeblog.getPost

    • metaWeblog.editPost

    • metaWeblog.getRecentPosts

    • metaWeblog.getCategories

    • mt.setPostCategories

    • mt.getPostCategories

    • mt.getCategoryList

    • blogger.getUsersBlogs

    • blogger.deletePost

    For this to work, I have created a reusable XMLRPC library for guile. More on this in next post.

These hacks are not yet available in tekuti's master, so you can get them from my branch:

git clone git://gitorious.org/~aleix/tekuti/acf-tekuti.git

Happy new year and happy hacking!

Syndicated 2011-01-10 00:24:11 from aleix's blog

new year, new blog: spreading the word with tekuti

This will be my last post in wordpress.com after using the service since 2006. At the time of this writing the blog has received 27122 visits which is not very much, but at least it means someone is reading (…may be the crawlers?).

WordPress is provided with statistics, anti spam filters, themes and much more (that I do not really use)… So, why am I leaving? Simply, because I want to learn new things (I’ve been feeling quite stuck lately). But, shouldn’t I be worried with the “what” instead of the “how”? Like solving the problem instead of worrying about the language I use? Well, I guess so, but I like to learn new languages even I don’t solve any problem (at the end this is not true, but I don’t want to get recursive here).

My new blog (http://hacks-galore.org/aleix/blog) is based on tekuti, a weblog software written in Scheme, using Git as its persistent store. All axelio’s posts have been imported to the new blog, so don’t panic!

Happy hacking!


Syndicated 2010-12-23 00:22:55 from axelio

ropemacs and remote files (fuse)

This morning I needed to edit some python scripts from a local server at work and, as always, used the TRAMP Emacs mode, but immediately found a problem. A few months ago I installed the great python refactoring library rope and its Emacs mode ropemacs. It comes out that ropemacs asks you for the location of your rope project if it cannot find it (this always happens the first time you start a project).

TRAMP URLs look like this:

/ssh:user@server:/path

So, you can now imagine what happens when Emacs gives an URL like this to rope (which is a python library and doesn’t know anything about TRAMP URLs) as if it was a local file name…

Traceback (most recent call last):
  ...
  ...
  File "/usr/lib/python2.6/.../ropemode/interface.py", line 88, in open_project
    self.project = rope.base.project.Project(root)
  File "/usr/lib/python2.6/.../rope/base/project.py", line 134, in __init__
    os.mkdir(self._address)
OSError: [Errno 2] No such file or directory: '/ssh:user@server:/path'

The worst is that you are continuously being asked by Emacs to enter a valid rope project location.

The solution? Simply use the FUSE SSH Filesystem.

$ sudo apt-get install sshfs
$ sshfs user@server:path mountpoint

FUSE stands for Filesystem in Userspace. With FUSE you will end up editing remote files as if they were in your computer and the great thing is that you don’t need root access, so any user can mount a FUSE filesystem.

Update 2010/11/17: FUSE mounted directory can be unmounted with:

$ fusermount -u mountpoint

Syndicated 2010-11-16 18:27:08 from axelio

ropemacs and remote files (fuse)

This morning I needed to edit some python scripts from a local server at work and, as always, used the TRAMP Emacs mode, but immediately found a problem. A few months ago I installed the great python refactoring library rope and its Emacs mode ropemacs. It comes out that ropemacs asks you for the location of your rope project if it cannot find it (this always happens the first time you start a project).

TRAMP URLs look like this:

/ssh:user@server:/path

So, you can now imagine what happens when Emacs gives an URL like this to rope (which is a python library and doesn’t know anything about TRAMP URLs) as if it was a local file name…

Traceback (most recent call last):
  ...
  ...
  File "/usr/lib/python2.6/.../ropemode/interface.py", line 88, in open_project
    self.project = rope.base.project.Project(root)
  File "/usr/lib/python2.6/.../rope/base/project.py", line 134, in __init__
    os.mkdir(self._address)
OSError: [Errno 2] No such file or directory: '/ssh:user@server:/path'

The worst is that you are continuously being asked by Emacs to enter a valid rope project location.

The solution? Simply use the FUSE SSH Filesystem.

$ sudo apt-get install sshfs
$ sshfs user@server:path mountpoint

FUSE stands for Filesystem in Userspace. With FUSE you will end up editing remote files as if they were in your computer and the great thing is that you don’t need root access, so any user can mount a FUSE filesystem.

Update 2010/11/17: FUSE mounted directory can be unmounted with:

$ fusermount -u mountpoint

Syndicated 2010-11-16 17:27:08 from axelio

ropemacs and remote files (fuse)

This morning I needed to edit some python scripts from a local server at work and, as always, used the TRAMP Emacs mode, but immediately found a problem. A few months ago I installed the great python refactoring library rope and its Emacs mode ropemacs. It comes out that ropemacs asks you for the location of your rope project if it cannot find it (this always happens the first time you start a project).

TRAMP URLs look like this:

/ssh:user@server:/path

So, you can now imagine what happens when Emacs gives an URL like this to rope (which is a python library and doesn’t know anything about TRAMP URLs) as if it was a local file name…

Traceback (most recent call last):
  ...
  ...
  File "/usr/lib/python2.6/.../ropemode/interface.py", line 88, in open_project
    self.project = rope.base.project.Project(root)
  File "/usr/lib/python2.6/.../rope/base/project.py", line 134, in __init__
    os.mkdir(self._address)
OSError: [Errno 2] No such file or directory: '/ssh:user@server:/path'

The worst is that you are continuously being asked by Emacs to enter a valid rope project location.

The solution? Simply use the FUSE SSH Filesystem.

$ sudo apt-get install sshfs
$ sshfs user@server:path mountpoint

FUSE stands for Filesystem in Userspace. With FUSE you will end up editing remote files as if they were in your computer and the great thing is that you don’t need root access, so any user can mount a FUSE filesystem.


Syndicated 2010-11-16 16:27:08 from axelio

Land of Lisp: Come back here, you cowards!

I must admit it, I just don’t know Common Lisp, nor Scheme, nor any other Lisp dialect, only some notions and ideas. However, I’ve been always fascinated with the people behind them and with their defense on what they say is the most powerful and beautiful programming language. Articles, user groups, books, conferences… and basically a lot of fun.

Today, even I do not understand most of the articles in LtU, I wrote about the Land of Lisp. Check out the music video and interactive comic (note: this is not for everyone).


Syndicated 2010-10-29 15:47:00 from axelio

More on easy acronyms generation

About four years ago I posted an article about easy acronyms generation in LaTeX. Yesterday, I did some updates to the script (tex-acronyms.py) that I wanted to share with you (if anyone is reading…). Basically, the updates are:

  • A user defined acronyms file can be specified via the -u argument. User defined acronyms take precedence over global acronyms definition.
  • Global excluded acronyms file has been removed. Now, the user must define acronyms to be excluded in the user defined acronyms file as an empty acronym. For example:
    \nomenclature{GHH}{}
    

    Then, the definition of GHH will not be included in the list of acronyms.

  • To facilitate the read of acronyms conflicts, it is now specified if the conflict is because of a “Duplicated“, “Undefined” or “Excluded” acronym.

So, the script is called as before but a new optional argument -u can be specified for the user defined acronyms file:

tex-acronyms.py [-r] -d /path/to/acronyms \
                -i article.tex \
                [-u user_acronyms.tex] \
                -o acronyms.tex \
                -e acronyms.errors

Syndicated 2010-10-22 05:59:35 from axelio

54 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!