Skip to content

Recent Articles

24
Mar

Slumdog Maiznet

This week-end I participated to the Federez days as a Maiznet Representative, and it was quite an interesting exchange of ideas and experience with other student network associations. If you are a French student network association, you should be joining Federez :)

I also happen to have been giving a presentation about what I learned and remembered in Maiznet over my years of participating and running it. You will find the slides over here :

I’m sorry for non-French speakers, but this time it’s plain French all over ;)

Now Maiznet and all that stuff is quite behind me, however I’m glad I had a shot at doing this!

30
Jan

Python run-time mixins

Don’t ask my why, I started considering to use some sort of “dynamic mixins”: what if you want to be able to mix a class into another during run-time, only for a single instance of my object. To illustrate this, here is some code example of what I try to do:

class Blendable(Blender):
    pass

class BlendMe(object):
    def works(self):
        print("Works for a")

a = Blendable()
b = Blendable()

a.mix_in(BlendMe)

# a should have the "works" method
a.works()

# but b shouldn't
try:
    b.works()
except AttributeError:
    print("Works for b")

Well, I have implemented this Blender class, here’s the result:

class Blender(object):
    def mix_in(self, chili):
        if not isinstance(chili, type):
            raise TypeError(
                "Blender.mix_in(): you can only mix in types, got %s.%s instead" % (
                    chili.__class__.__module__,
                    chili.__class__.__name__
                )
            )

        newtype = type(
            "%s_%d" % (self.__class__.__name__, id(chili)),
            self.__class__.__bases__,
            dict(self.__class__.__dict__)
        )

        newtype.__bases__ = self.__class__.__bases__ + (chili,)
        self.__class__ = newtype

I’m not sure I’m going to use that for real, but the concept is surely funny. Leave me some comment if you ever need to use something as crazy as this :)

You can get the full file here.

12
Dec

HTML5′s localStorage as software bus

I keep wondering what goes through my mind. Today I stumbled across HTML5′s localStorage facility, and I was immediately seduced by the possibilities it offers. I don’t know which ones, but surely they are huge!

One of the things that I could think of and that might open up a whole new sky is that thanks to the “storage” event, you can actually use this localStorage as a software bus between your Javascript pages. IPC in the browser! Am I too enthusiastic? Probably, but I’ll still show you a small example that I put up and that I think is quite fun :

All right, you think it is a dead text field? Just try opening this page again simultaneously in another window. Put the two text boxes side to side, and start typing into one of them. Profit :)

How does the magic work? Easy, you can store any string into the localStorage object (just use it as an array), and when it is modified by one page, all the other pages receive a storage event that tells them that a new value was added. So basically, the code to do this is extremely simple. Here are the useful parts of it, made out of jQuery and Angular.js for the sake of awesomeness.

                <div class="container-fluid">
                        <div class="main-box" ng-controller="localBusCtrl">
                                <h2>This field is...</h2>

                                <input type="text" ng-model="busValue">
                        </div>
                </div>
(function ($, ng, localStorage) {
	'use strict';

	ng.module('localBus', [])
		.controller('localBusCtrl', function ($scope, $window) {
			$scope.busValue = localStorage.busValue || "magic";

			$scope.$watch('busValue', function () {
				localStorage.busValue = $scope.busValue;
			});

			$($window).on('storage', function (e) {
				$scope.$apply(function () {
					if (e.originalEvent.key === "busValue") {
						$scope.busValue = e.originalEvent.newValue;
					}
				});
			});
		});
}(jQuery, angular, localStorage));

Basically, how does it work?

  • Read the initial value from the localStorage (which is persistent across page reloads etc)
  • If the input field gets modified, write the new value into localStorage
  • If you get a storage event, update the input field’s value

Couldn’t be any simpler :)

Now that this is done, I wonder what else could be invented. Mutualize XHR between instances of a page? Synchronize some content? Create a chat system for schizophrenic users? Time will tell if I find anything useful to do from this!

Many thanks to Dive Into HTML5, from which I got everything I needed to know about the localStorage!

11
Dec

Ponytile !

Hey, it’s been a while :) I’ve been kind of busy for the past year and with some non-technical stuff, but programming is back in my life and that’s for the best!

I wanted at least to write something before the world ends. Well, this leaves me up to 2038, but you’d better be prepared!

Anyway, today we’re talking… CSS Sprites. Why? Mainly because I’m a great fan of the idea: you can just lazily insert images in your HTML with CSS classes, and this is a lot more friendly than inserting <img> tags by hand. Basically, you just put a CSS class, and you’re done, like this:

<i class="img-toto"></i>

Also, with all the files being in a single file, you get only one query to fetch most of the icons/buttons/stuff of your page, which is a quite noticeable win in terms of page load time. Not for the server side, but for the client-side load time. If you live in some remote place or use a high latency connection (3G…), you’ll notice the difference pretty easily.

I’m done with theory, there is about a gazillion links on that matter if you want. Rather than that, I will introduce quickly the new tool I developed in order to generate those tiles. Let me then introduce you Ponytile!

But first, just why? Hum, well there was no tool that made exactly what I wanted them to do (I actually secretly plot to integrate that into Django Pipeline, but shhhhh). After Googleing a bit more, Glue might have worked out, but it’s too late now that my code is written. This brings me to the other reason: it was fun and quick to make.

So, how does it work? The big picture is:

  1. Grab a few image files
  2. Generate a single image file with all those images on it
  3. Generate a CSS file with the classes for all those images

Everything here is trivial, but the 2d part where you have to do some floor planning. For the needs I can foresee here, I felt like doing something extremely simple and stupid: take the pictures one by one and put them in the left-topmost position you can find free for it. In order to simplify things, the unit is not the pixel, but a block of 16x16px (or whatever is configured). It turns out that despite its huge big-oh complexity, this algorithm is fast enough for any number of pictures you’d want to put on a single web page. Fair enough!

What else can I add? Most of anything else on how to use Ponytile is listed in its README, so I won’t repeat it here. I have no real-world example yet, but this might come someday :)

Oh and it’s also a Pypi package that you can install with pip:

pip install Ponytile

Doing so will provide you with the ponytile CLI tool, as well as the library package.

In between, if you have some suggestions or you want to contribute, feel free to do so on GitHub. The license is the WTFPL as always, then feel free to do what the fuck you want to.

19
Nov

Debian’s stupid ntpd

Lately I came to notice that my computer’s time began to drift irrationally, although I have ntpd running. I have the default ntpd.conf, and in particular with this servers list:

server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst

So why in the world would my time drift? This configuration has been working fine for years. I began to check the synchronization using ntpdc:

ntpdc -c peers

And there, I saw only one line, telling me that I peered with 172.17.0.2. For instance, my network is 192.168.42.0/24 and runs no ntp server, so there is a bit of a problem here. In fact, I went to someplace where the DHCP announces a ntp server, and the configuration was kept ever since.

Thus, a very simple solution exists:

sudo rm -f /var/lib/ntp/ntp.conf.dhcp
service ntpd restart

And now everything is well:

17:57 remy@magi ~ % ntpdc -c peers
     remote           local      st poll reach  delay   offset    disp
=======================================================================
*2a01:e0b:1:88:2 2a01:d35:213d:8  2   64  377 0.02591 -0.028799 0.03157
=thor.netservice 192.168.42.129   2   64  377 0.14030 -0.028539 0.03108
=utility-lax.rac 192.168.42.129   3   64  377 0.19328 -0.016656 0.03149
=isaachayes.khre 192.168.42.129   2   64  377 0.18999 -0.020809 0.03113

We’ll note that it furiously looks like Debian’s #569775 bug.

16
Nov

Howto not crash Cisco’s NAT

Maiz is the dormitory of my school, and it hosts around 170 people. As a school of network & telecom, it is only natural that us students manage our own network, and so do we.

However, we suffer from severe bandwidth limitations. Indeed, because of many factors, we can only have a few ADSL lines. Still, we try to give our comrades a decent Internet connection, but with only lousy Netgears modems (see the previous post), it’s quite difficult to get the network to scale up.

So the current challenge is to find modems that will not crash after a few hours/minutes. To give you an order of idea, there is approximately 20 connections opened each second. We have to reboot the Netgear every 20 minutes in order to keep it alive…

Then we tried a Cisco 1700 with a modem card. It goes fine, but however crashed after a few hours. Reason ? Too many NAT entries and no RAM left. And indeed, Cisco’s timeouts are really, really conservative: the default TCP timeout is 24 hours. After setting those to more reasonable values, it seems to work better!

ip nat translation timeout 3
ip nat translation tcp-timeout 600
ip nat translation udp-timeout 120
ip nat translation finrst-timeout 3
ip nat translation syn-timeout 10
ip nat translation dns-timeout 3
ip nat translation icmp-timeout 3
ip nat translation max-entries 30000

You’ll note the last line setting the max-entries. Its purpose is not to limit the users, but to have the router to refuse connections before it gets out of memory.

I can’t wait for IPv6 and for this f*cking NAT to be dead! #optimistic

13
Nov

Why is Microsoft going to fuck everyone’s back?

Before anything, I’m far, far, very far to be a Microsoft fanboy. However, I lately came to (re-)discover things made by Microsoft that make me think that they are not the club of incompetent idiots that everybody tends to take them for.

By example, it’s of common knowledge that Microsoft did never invent anything and did copy all its products on its competitors. Really ? We’ll have a quick tour :

  • Peedy the Talking Parrot (1995). Have you ever heard of him ? Well, it’s a parrot able to understand natural language to execute various tasks. In the video demos, you can see how you could control your music player using natural language sentences, and get a human-like answer (including expressions). Doesn’t it quite remember Apple’s Siri ?
  • The Briefcase. You can put documents in it, and then synchronize them between computers. It appeared at least in Windows 95, and seriously reminds of Dropbox.
  • Microsoft’s vision of Internet in… Windows 98 installer. Remember those texts that the installer displays in order to make you wait by teasing you on how awesome Windows is. If you read them with today’s eye, they mostly describe a vision of Internet where you can do e-shopping, have a virtual identity, etc. This vision is being realized, but its accomplishment is not even finished!
  • Microsoft Bob. All right, this one is even worse than an EPIC fail, because they actually tried to make the computer look like all other common objects with the technology they had back in the time. You can’t fit a house in a screen. But you’ll fit all sorts of electronic devices, corresponding to Bob’s applications, inside your house. That’s exactly what ubiquitous computing is about! We’ll note that ubiquitous computing opposes itself to virtual reality, but I explained the relation I see between the two.

So, why a few 20-years old epic fails would mean that Microsoft is not staying in his grave? After all, as we do all know, they splendidly missed the Web 2.0 thing, and that’s what puts them in a “bad” position. But is it really a fault? Why did they need so long to get Internet Explorer back on tracks? Firefox probably stole 20% of their market share before they woke up. Don’t tell me that one of the largest company in the world can’t get a web browser right. Ironically enough, we’ll note that the whole Ajax/Web 2.0 hype relies on one and single thing: the XHR object, that was introduced by Microsoft.

But maybe that they see on the longer term. If no Web 3.0 is coming out (shut up you troll in the back), it’s probably because the Web 2.0 is merely a transition to something else, that is, once again, ubiquitous computing. See the smartphone/tablets delirium that’s floating around? It’s only the beginning.

And for 20 years, Microsoft did not make a move on anything. They just polished their Office pack, killed GPU for Aero to work and other superficial stuffs like that. Fundamentally, Windows 7 does nothing more than Windows 3.11, if you make abstraction of the technical side of things. But for 20 years, Microsoft Research was not shut down, and you sometimes see them surfacing. Like Surface, or all the thing’s they’ve been doing on robotics. Those things are still in the labs, because they’ve learned of their mistakes and now they’ll wait for the market to be ready before to take a product out.

The first strike: the Kinect of course. What’s next? Who knows… My belief is that they’ll use a strategy similar to Apple’s. When a new product starts to take off (like smartphones by example), they commercialize a new product more advanced than all of the others (at least, marketingly speaking).

In other words, if you’re going to do new products, watch your back, because Microsoft probably has a better one in its labs!

There is however another possiblity: Microsoft guys are indeed plain idiots, and thus Microsoft Research did never manage to get anything working, which means that in 10 years I’ll re-read this post and roll on the floor laughing to be so wrong. Time will tell :)

8
Nov

“Modem” (= bridge) mode on Netgear DG632

Recently I configured a Netgear DG632 in a bridge mode. Initially I was expecting the modem to translate from PPPoE on the LAN port to PPPoA on the WAN port. Wrong :)

In short, the configuration :

                                             ---- Machine 1
((Internet))----[ DG632 ]----[ Gateway ]----|---- Machine 2
                                             ---- Machine N

Actually, it dials the ISP and identifies itself just as in the router mode, but the difference is that it expects to find a computer with the public IP on the LAN port. However the router that you gateway must use is not the one given by IPCP, and rather the management IP of the modem. Here’s the relevant part of my FreeBSD’s rc.conf:

ifconfig_re1="inet 193.251.78.150 netmask 255.255.255.0"
static_routes="adsl"
route_adsl="-host 192.168.1.1 -iface re1"
30
Oct

KVM-ized Debian on LVM

The question of storing virtual machines datas has a lot of answers, but only a few seems to be as flexible as what you’ll find on a plain old physical machine.

First try

For instance, what I looked for was to be able to have a storage pool inside of which I can extend partitions sizes as needed, because I host several services with relatively unpredicted expansion.

Usually when you need to do that, you can use LVM, and hot resize you partitions. However, the virtual world is not so simple, and this can’t be done directly. My first try was to have my standard LVM pool in which I would create the logical volumes I need, and then add them as independent disks.

This appoach works, however the Debian installer requires that you create a partition table, which makes it pretty difficult to use from the host, and moreover is almost impossible to resize.

A few commands

Imagine that the volume storing your virtual hard disk is the LVM logical volume /dev/mapper/myvm-root. First you have to tell the kernel to map the devices from the partition table:

kpartx -a /dev/mapper/myvm-root
ls /dev/mapper/myvm-root*

This shows you that your partitions appeared in the mapper. You can now use them as usual

mount /dev/mapper/myvm-root1 /mnt

But now if you want to resize the hard disk, you have to resize your LVM volume, but also to make the change in your partition table. As nobody has ever heard of size-changing hard disks, I don’t know any tool that does this, so unless I missed an option somewhere, it’s pretty much fucked up for you.

Better solution

In fact, you must create the partitions beforehand, so the installer sees them and can use them without creating a brand new partition table. And you can see the partition directly from the host.

A few other commands

Once the logical volume is created, you can format it the standard way:

mkfs.ext4 /dev/mapper/myvm-root

Then when you launch the Debian installer you’ll see the partition as already existing, and won’t be prompted to create a partition table:

Once your Debian is installed, you can just mount the partition(s):

mount -o ro /dev/mapper/myvm-root /mnt

Or if your VM is down, you can even resize the volume

lvresize -L +1G /dev/mapper/myvm-root
e2fsck -f /dev/mapper/myvm-root
resize2fs /dev/mapper/myvm-root

Then when you reboot your VM it will have got a 1 gigabyte bigger hard disk.

Other Approaches

This is certainly not the only way to achieve the goal of be able to dynamically resize your hard drive. For instance, you could probably manage something with qcow2 disks growing as needed, or maybe create several disks that you aggregate as physical volumes, or who knows.

But the solution I found here is what I found to be the more practical to use, without loosing too much performances. Still, you can’t do hot resize, and this might be a problem for some people, but I don’t see how you could hot-resize virtual disks. I guess it’s a feature to come!

Anyway, if you know a better way to get this done, I’m quite interested in it ;)

28
Oct

New Project: Karte

Nothing ground-breaking today, I’m just starting a new project. Once again it’s university-related, and this time it’s going to have a real-life application. Indeed, the goal is to create a payment card for all pupils. It’s going to allow electronic micro-payments in various places and occasions (parties, cafeteria, …).

There will be a client, used on the points of sale, and a server, probably backed-up by a PostgreSQL database. The client is going to use Qt, and the server will use the very good Twisted framework, that is a Python framework that allows you to easily create and deploy network applications.

For now the only thing more or less advanced is the data model, created using the Django ORM and Modelviz. We probably won’t use the ORM at all, but it helped to design the database without loosing too much time with poor database design tools. And it generates both the graph and the SQL!

Regarding the “card” technology in itself, it’s probably going to be RFID/NFC. Not because it’s hype, but because it’s cheap and the student card is a NFC anyway, so we’ll try to use it! And by the way, NFC is quite the same thing as RFID, it’s just that RFID designates a wider range of technologies than NFC. In case you are being confused, it’s just marketing, not technology.

Anyway, since I’m being evaluated on this project, I’m pretty sure I will finish it, or at least greatly advance it. So stay tuned to see how it turns out :)