Guillaume “Zifro” Desrat’s former blog

HTTPS blocked ? Use secure HTTP authentication then !

Filed under: code — Zifro November 30, 2006 @ 12:55 am

Alexis, an active member of Ruby France (you know, the French guys fond of Ruby), has set up a blog on blogspot.com : Alexis’ notes @ http://alexis-notes.blogspot.com/.

We only discussed Ruby code and software design twice (as far as I remember), but I was impressed by his knowledge and the way he quickly solved a problem by offering to use a Mediator design pattern.
I’m looking forward reading some Ruby code he gonna write !

In his first post, he writes a proposal to put an end to unsecure HTTP authentication, without HTTPS. I haven’t tested it yet, but it makes sense to me when I read it.
I strongly encourage you to go and read his proposal, comment his ideas, and go back later to read more on his blog.

DSL with Ruby : how to get a step ahead ? (make it written in French, for my colleagues’ sake)

Filed under: work, WinDEV, code, Ruby — Zifro November 29, 2006 @ 12:50 am

DSL is the acronym for Domain Specific Language. A DSL is a language designed for a particular purpose, for an intended audience who may not feel fine with a complex programming language. For example, Microsoft Excel macros are part of a DSL.

I’m currently working on an application which exports data into a text file, formatted with given tags and given parameters, then send it to another remote software, which will handle it (I skip here the whole process, which isn’t interesting at all for those who don’t work on it) to finally have the data printed and sent by mail.

WinDEV doesn’t offer built-in testing, so I made the application write a checksum like log, to verify the number of each type of data exported. Well.
But as we’ve got several undocumented (yeah, I know, real developers don’t write neither documentation nor comments, I should just read the code…) data handling rules, some of the corrections I add last month made errors appear in other parts of the file generated.
At this point, it gets enough freaky for me. I NEED REAL TESTS !

So, I decided to write, on my spare time, a tool to validate the file (if fields are all filled, if the values make sense, if the email field really contains an email address, and so on). Playing with metaprogramming and code injection, I got this skeleton of testing code (hiding all the automagical thingies in FileAnalysis.rb) :

#!/usr/local/bin/ruby -w

require "FileAnalysis"
include FileAnalysis

trap('SIGINT') { puts "\n\nAborting tests...\nBe sure to run *ALL* the tests at once from time to time ;-) \n\n"
exit
}

FileForPrinting.is "MMMMMMMM_data_2006_11.txt"
FileForPrinting.analyze do |line|

line.store? do |mag|

store.should_have_all_fields_filled
store.should_have_a_valid_email_address

end

line.cust? do |cust|
# here goes the tests for customers lines
end

line.art? do |art|
# here go the tests for article lines
end

end

This looks like a DSL to me (and it’s pretty like “Creating DSLs with Ruby” on Artima.com). Tests are quick to write, and fully understandable (okay, for those who know which tags are in the file, and which tests could apply to those lines).

Unfortunatly, my colleagues, who’ll have to deal with this piece of code, sooner or later, aren’t… English-friendly :)
For one thing, we don’t write code in English at work (WinDEV is set to “I code in French, pal” mode), and they’re not used to read and write this language. On the other hand, I don’t feel comfortable with writing tests in English for something I work on daily, in French. I mean : why the hell would I write line.store? instead of ligne.magasin ?

So I’ve the idea of pusching the DSL work one step further, turning it into a French written test tool, which would look like :

FichierAImprimer.est "MMMMMMMM_data_2006_11.txt"
FichierAImprimer.analyse ligne par ligne

ligne de type magasin ?

la ligne devrait avoir tous les champs remplis
le magasin devrait avoir une adresse electronique valide

ligne de type virement ?

...

fin des tests

Okay, that would be very cool. Of course, I might end up writing slightly different code lines, to save some time working on that, but I think you get the idea. I suppose I’ll call a method, just after starting the program, as the first line of the code, to parse the file (or, maybe another one which will contain the tests) to replace some strings by another, according to rules I’ll set up (delete a blank space if it is immediately followed by a “?”, “le” and “la” at beginning of the line should be deleted as well, and so on…).

This would mix the two categories of DSL : the ones which are new dedicated languages to serve one goal, and the ones which are evolution of existing programming languages.

At this point, I have only two questions to you, readers : have you ever written a DSL to be used by non-English people, and what’s your opinion about all this ?

Eclipse, the lightweight IDE

Filed under: code — Zifro November 8, 2006 @ 11:25 pm

Eclipse is light. Here is the top command output on my machine, after running for one day :

load averages: 1.31, 1.36, 1.38 20:17:15
48 processes: 2 running, 44 idle, 1 zombie, 1 on processor
CPU states: 88.8% user, 0.0% nice, 11.1% system, 0.2% interrupt, 0.0% idle
Memory: Real: 310M/491M act/tot Free: 8176K Swap: 38M/256M used/tot
PID USERNAME PRI NICE SIZE RES STATE WAIT TIME CPU COMMAND
5362 zifro 64 0 244M 205M run - 341:47 54.15% Xorg
27702 zifro 2 0 96M 94M sleep poll 588:48 37.06% firefox-bin
32490 zifro 2 0 2604K 4832K run - 28:44 4.05% xmms
21058 zifro 2 0 429M 22M sleep poll 9:16 0.00% java
5990 zifro 10 0 288K 4K idle wait 0:00 0.00% eclipse
2974 zifro 2 0 5340K 9620K sleep poll 4:49 0.00% xchat
18904 zifro 2 0 13M 17M sleep poll 0:29 0.00% thunderbird-bin
18220 zifro 2 0 2484K 3048K sleep select 0:18 0.00% fluxbox
650 zifro 2 0 20M 21M sleep select 0:07 0.00% ruby

See ?
JAVA is bloated, not Eclipse :-D
But I started using it with RADRails under Windows, and I like it. When I stopped travelling in Europe and got another job, I had to give back the laptop I used to work on, so I migrate my development tools under my good ol’ OpenBSD workstation at home.
I spent hours compiling Java, installed the Eclipse package, added the Ruby Development Tools plugin and finally the RADRails plugin, in order to enjoy the same environment again.

Before Eclipse, I was a long time SciTE fan, opening many windows and terminals, to edit my source files and run the scripts needed.
And in older times (back when I was a Linux newbie, which I’m not any longer, since I’ve been an OpenBSD newbie for four years now), I used gvim.

Based on my following requirements :

  • syntax coloration for many languages/frameworks (C, Perl, Ruby, Rails, …)
  • panel for directory listing
  • panel for class/code analysis (like Eclipse’s Outline)

what would you advise me to use now ?

Let’s communicate

Filed under: code — Zifro October 16, 2006 @ 9:57 pm

Modular, distributed, pluggable, extendable.
Today applications are more communicating than ever. They offer to exchange data internally (modules, plugins) or externally (distributed computing, communication with other programs).

More than a fashion, developers now tend to make their application comunicate (who never yelled because he or she  couldn’t work with a good app just because it wasn’t opened to the world ?).

fredix works on Gtk signals to perform actions in his killer-app, Geekast, a gnome interface to Peercast.
jd and guiguilinux are starting a new implementation of dbus, a library aiming at making applications communicate.
And I’m working on a modular framework, as written here before :)

The result ?

We’ll soon or later provide frameworks, documentation and howto for the community !

uKR : a framework for developing modular Ruby applications

Filed under: code, Ruby — Zifro September 19, 2006 @ 1:55 pm

As I wrote in this previous post, I’ve started working again on some Ruby code.

I’m currently extracting the micro-kernel part of YAIB to turn it into a framework for developing modular Ruby applications.

The goals of the project (simply called “uKR” until I find a good name) are to provide a complete-but-expandable, clear and clean, well-documented and well-commented, framework for event-driven modular applications.

A modular architecture based on an applicative micro-kernel allows the developers to share the tasks between each others, code separate stuff with a common communication message (read about it on OSNews).

It also allows to intercept crashes : if the sound module of an application has unexpectedly terminated, the micro-kernel is up to detect it, and rerun it a number of time.
It can also handle updating running applications : a module downloads its update, ask the micro-kernel for being reloaded ; its message queue is saved, the module is reloaded, given back its message queue, and run.
Other idea : a module can choose to offer many services to other, like authentication ; it sends messages to other modules anytime someone logs in, like “hey, this one is approved, you can process his/her requests”.

Truly, there are many applications of the micro-kernel paradigm to software applications, not only operating systems. Of course, I haven’t detailed why some people *HATE* them, I’ve just explained why I’ve used it for YAIB and why I’m about to write this framework.
Want examples ?

A multimedia player : one module for the user interface, sending events like “play”, “pause”, “next”, “stop” events to the module playing the music or the video, while another one is downloading the new version of the UI module.

An IRC bot : one module handle the connection to the server while other focus on dealing with channels managements, authentification, serving news to chatters, …

The first work is to clean the code from what hasn’t to be in, and re-design some of the internals, with the developer needs in mind. If you have any idea about it, please leave a comment or email me (zifro@).

I might release it (in an early version) by December (at last !).

YAIB will be based on it - sort of “hey, look, it works” application - as soon as it becomes usable.

PS : thanks anamorph for having motivated me yesterday. You’re a friend to me.

Tuesday, WinDEV.

Filed under: work, WinDEV, code — Zifro September 12, 2006 @ 1:46 pm

As I was to find out a solution to the big number problem in our software, I imagined I could write the code in Ruby, make it stand-alone with rubyscript2exe, and call it from WinDEV.

*Laughs*

The Ruby part went fine (of course), but I couldn’t manage to get something else than 0 when I call it from WinDEV. And then I noticed that I forgot a blank space, so instead of calling “C:\zlab\rlmc.exe 8708″, it was launching “C:\zlab\rlmc.exe8708″, FUCKING SILENTLY !

So after some tests, I went to this conclusion : one of the two signatures of the LanceAppli function doesn’t work (by work I mean raise and exception in such a case).

If you’re interested in knowning more about it, here you are :

My advice : DON’T MESS WITH WINDEV OR YOU’LL GO INSANE !

(and finally, I coded an int z_modulo(string s, int n) function to keep all the code in WinDEV)

Monday, WinDEV.

Filed under: work, WinDEV, code, Ruby — Zifro September 11, 2006 @ 5:59 pm

I’m currently working on software to help our customers save time, by extracting data from their databases, to generate a big file and then send it to a partner, who’ll print all the letters and checks.

Honestly that’s a big advance for our customers, something like one day work saved.
But as my company will handle some of the administrative part, I have to write the checks parameters, like the name, the address and stuff.

One of these parameters is the (sort of) checksum of the magnetic ligne at the bottom of the check ; it aims at checking the check authenticity.
The algorithm I was given by our bank director office is the following :

rlmc = 97 - (N x 100 - 97) where N is the concatenation of the 31 digits of the magnetic line (check number and two bank codes).

So I code it, run it, and WinDEV : string to number convertion and big numbers handling TADA !
It appears that WinDEV doesn’t handle big numbers (string to number convertion sucks hard too).

So, “just to try”, I typed in the same thing in irb :
irb(main):001:0> s = "6459010034010041908006791980430"
=> "6459010034010041908006791980430"
irb(main):002:0> rlmc = 97 - ((s.to_i * 100).modulo(97))
=> 54
irb(main):003:0>

Oh… it works :p

Don’t fear the bot (”Thou shalt op me !”)

Filed under: code, Ruby — Zifro August 20, 2006 @ 9:43 pm

It’s Sunday evening, my sister came to visit me (and browse the Internet for a job offers) and I’m writing this post while she’s watching Ocean’s Eleven.

I updated the system and the applications on my mother’s laptop, removed what was useless, cleaned the hard drive and KaoLLa tested it all the afternoon. Cool, it works well, a bit faster than before (even with the Service Pack 2 installed). Now I’m using it to write this post. Strangely, I always experience difficulties to access Free.fr pages from my OpenBSD box, and it seems to work fine with Windows XP. Weird, no ?

So, the main topic of this post is the IRC bot I have developped for years (which doesn’t mean it is fully usable, featuring cutting-edge mechanisms (err… in fact it does) and all stuff. Here is the story :
I coding a Perl IRC bot in 2002 March-April, then started writing another with Ruby, which I discovered thanks to Maz (not Matz heh !).
After he dropped the development at an early stage, I kept on working on it from time to time, when I wanted to. Firstly named “MiKeRWIB”, for “Micro-Kernel Ruby Written IRC Bot”, I separated the IRC library from the micro-kernel (it wasn’t a true, pure, one before), and renamed it “YAIB”, a recursive acronym standing for “YAIB is Another IRC Bot” (too bad someone already used “Yet Another IRC Bot”).

This bot features a micro-kernel, an IRC library and a skeleton for user-made modules. Because by itself, the bot doesn’t do anything. It needs a module to connect to an IRC Server, call the IRC messages transformation process and send those to the other modules via the micro-kernel. This one dispatches the messages to the running modules, which it shares messageboxes with, and grabs messages from those ones to send them to the IRC server, via the CONNECTION_MODULE.

Is this clear ? Does it make sense to you ?

The module skeleton system helps the user (also called “the developer” at this point, because YAIB aims at being used by IRC bots developers) save time (and energy) by hiding all the magical mechanisms like transforming a call to the method “join” into the creation of a JoinMessage, formated in order to be sent, then passed to the micro-kernel for being delivered to the CONNECTION_MODULE, and then sent to the IRC server. It’s sort or “role-based” or “aspect-oriented” programming. I learnt that after I coded it :p

These last days, kedare on #rubyfr @ Freenode asked for things to code, and I helped him writing a simple module. He went on and developed a complete module to manage one of his channel (well, as far as I know, that’s what he did).
Then guiguilinux on the same channel showed us a Ruby script to translate morse code to human-readable characters both ways, which I ported to a YAIB module (it has been intensively tested on IRC by many folks who played with it ’till I disconnected the bot).

So I’m truly happy to see people try and enjoy what I code :D

If ever you’re interested in this project, let me know (by commenting, emailing me at [zifro] _at_ [yaib] _dot_ [net], or hanging on Freenode (I’m always on #rubyfr and #ruby-lang).

As part of my night courses, I’m (slowly) developing yaib.net and yaib.org websites with Ruby on Rails. The first one will present the project, display the day-to-day changelog, the development news, offer documentation and downloads ; the second will be sort of RAA, allowing developers to share and promote their modules. I try to stick to the idea of making them both clear and simple (without Javascript, without CSS hacks) since I have another Web 2.0 (current buzzword !) Rails website : Hazzard community’s one.

For the impatient ones, you’ll find something to download and run at http://yaib.net/ . Although it requires you to tune the IRCConnection.rb file to connect where you need, and the Services (another nice feature) to be turn off, it’s a toy you can play with and use as you like. Last words : it requires Ruby 1.6 or later and it’s released under the GPL (which might be changed in a near future…).

New project, new horrific code lines

Filed under: work, WinDEV, code — Zifro August 7, 2006 @ 12:00 pm

I’m now working on a new project. Well, it’s something new for me, but the software I’m diving into has been used for years to retrieve data from our shops each night.

The code is pure shit.

For example, there is a procedure that compare two dates, contained in two global variables, and returns the result in the variable passed as parameter. See :

procedure compare_dates (result)

// comparison code…

result = …

Better seeing that than being blind, hu ?

WinDEV sucks (again)

Filed under: work, WinDEV, code — Zifro May 22, 2006 @ 1:00 pm

Yes, it sucks. I played a bit with its Object-Oriented features… damn ! You can’t test the class the objects belong to (typevar returns wlInstance and nothing more) , you can’t create objects and send them to a method (you must tie them to a var)…

You don’t use ::Creator, but var = gimme a (yes !).

Sorry, PC Soft guys, this is not what I call OOP.
Well, maybe it’ll be fixed in WinDEV 30, but it depresses me a lot to work with that.

- Next Page >>>