Saturday, July 23, 2011

Give my luck back, Firefox 5!

Today I've upgraded to firefox 5, special thanks to Debian developer for packaging it. So far, everything works well and better than before, except two things (one of which I managed to tweak):
  1. The tabs bar is higher than before. This means that the mouse must move more to reach them. This has been solved. Thanks for allowing me to put the tabs bar below back again.
  2. The address bar no more involves "I feel lucky" search. The feature was awesome, because I often write a partial website name and I get most of the time to the right page without actually typing the whole name. Also, since we already have a search bar on the top-right, why was this feature removed? It's kind of duplicated now.
So, dear readers, do you know of any add-on so that I can have "I feel lucky" search back, before I write one? Having it on the top-right bar is good as well.

Edit: The solution is to open about:config and set the keyword.URL value to "http://www.google.com/search?btnI=745&q=" (without quotes). Thanks to Giuseppe for the hint.

Saturday, July 09, 2011

Python/Ruby like generators in Vala

Hello,
the post below is copied straight from here.

Here I'll show a cool snippet code making use Vala async functions and iterators for emulating Python/Ruby generators. Creating a generator is as simple as extending the Generator class and implementing the generate() method.

abstract class Generator {
    private bool consumed;
    private G value;
    private SourceFunc callback;

    public Generator () {
        helper ();
    }

    private async void helper () {
        yield generate ();
        consumed = true;
    }

    protected abstract async void generate ();

    protected async void feed (G value) {
        this.value = value;
        this.callback = feed.callback;
        yield;
    }

    public bool next () {
        return !consumed;
    }

    public G get () {
        var result = value;
        callback ();
        return result;
    }

    public Generator<G> iterator () {
        return this;
    }
}

class IntGenerator : Generator<int> {
    protected override async void generate () {
        for (int i=0; i < 10; i++) {
            yield feed (i);
        }
    }
}

void main () {
    var gen = new IntGenerator ();
    foreach (var i in gen) {
        message ("%d", i);
    }
}

You can find the above code snippet here as well.

Tuesday, July 05, 2011

Why I'm still using Emacs

Hello,
I'm using emacs since a long time by now. Everytime I ask myself why I'm using it, given emacs certainly isn't the easiest environment for programming. So, I often tried to replace emacs with other IDEs or editors, using several extensions and so on, but I still miss these killer features in a single editor:
  • Pressing a key (whatever it is, TAB in emacs) correctly/smartly indent the row according to the current language.
  • Split view, horizontal and vertical
  • No horizontal scrollbar, rather wrap the text
  • Opening/closing files without either opening a dialog or using the mouse
  • Search, search and replace (also with regexp variant) without opening any dialog
  • Switching between buffers using the longest-common-subsequence matching, without using the mouse (i.e. I don't care about file tabs, but about switching among them fast)
  • Indent entire code regions
  • Vala, C, Python, Java, Shell, Autoconf/Automake, Make and Javascript support

So, I'm not using emacs because I love it, but because it's actually the only editor with the above features.

What I'm looking for? I'm looking for a new editor/IDE, less complex, easier to customize, having the above features plus smart completion and symbol browser.
Emacs can have completion and symbol browser as well, but managing those buffers such as speedbar suck a little, things get complicated to use and to customize.

If anybody knows of such an editor, please let me know :)

Thursday, June 02, 2011

Writing binary files with bash

Hello,
I'm trying to see if I'm able to write some binary file using bash. So, when writing a binary file you often want to write a number into binary format. I ended up with this simple function for writing numbers in little endian:

function num2bin() {
printf $(printf %.$(($2*2))x\\n $1|
sed 's/\([0-9a-f][0-9a-f]\)/\\x\1/g')|
awk -F '' '{ printf $4$3$2$1 }'
}


The first parameter is the number to write, the second is the number of bytes (up to 4). For example "num2bin 40 4" will output a 4-byte long string containing the number 40 in little endian.

How do we use it? I wrote an example script for creating a wav file with noise (according to wav specifications) that you can read here.

Let me know if you have a simpler version of the num2bin function.

Friday, May 27, 2011

Complete variables with cd command in bash

Hello,
lately I've been searching for a way to complete variables containing directories with the "cd" command in bash. This is very helpful if you have something like "cd $mydir/". This is not actually working in debian bash-completion.
Then I've realized that other commands such as "ls" actually expand variables. I looked for some "complete" combo used for "ls" but not for "cd" in /etc/bash_completion and I came out with the following:

complete -F _longopt -o default cd

Luckily, this is exactly the command needed to enable variable expansion with the "cd" command. Put that in your .bashrc after loading bash_completion and you're done.

Sunday, May 22, 2011

Enforce facebook chat through SSL

Hello,

since a few days facebook is supporting SSL for the chat. The problem is that it can't be enabled.

Until facebook enables this you can use the SSLGuard plugin for firefox, which enforces SSL for a list of web sites, including all facebook pages and the chat as well.

We have some good ideas for sslguard that we'd like to get in for the next releases... stay tuned.

Saturday, May 14, 2011

Valag 1.2 released

Hello,
I've just released the 1.2 version of Valag, the graph generator for analyzing Vala code trees. Only relevant change is the fact that it now builds against libvala-0.14.

More information and download at the Valag homepage.

Thursday, February 24, 2011

Bubble sort for prolog

Hello again,
this time I've found a version of bubble sort here. I wanted to provide my version, which is less iterative and, I think, more intuitive. What it does is, simply, bubble until it's sorted:

bubblesort(L1, L2) :- bubblesort2(L1,L2,unsorted),!.
bubblesort2(L,L,sorted).
bubblesort2(L1,L2,unsorted) :- bubble(L1,L3,C), bubblesort2(L3,L2,C).
bubble([],[],sorted).
bubble([X],[X],sorted).
bubble([X,Y|L], [X|L1], C) :- X <= Y, bubble([Y|L],L1,C).
bubble([X,Y|L], [Y|L1], unsorted) :- X > Y, bubble([X|L],L1,_).

Yes, the exam is tomorrow so I will finally stop annoying you readers ;)

Saturday, February 19, 2011

Aptitude string for downgradable packages

Hello,
I'm lately doing some tests with Debian experimental packages thus I often upgrade some packages to experimental and downgrade them back to unstable.
WARNING: Downgrading in Debian is not supported etc.

aptitude search "?narrow(?installed,?archive(experimental))" -F %p|\
sed
's,\([^ ]*\),\1/unstable,'|xargs echo


This will give you a list of experimental packages installed on your system each concatenated with "/unstable". The output can go straight to "aptitude install". I don't directly use "xargs aptitude install" because it's not interactive.

Tuesday, February 15, 2011

Matrix transpose with Prolog

Hello,
an exam exercise requires me to write a matrix transpose method. I've written one and it took a little before I was able to define it completely in 4 rules.
I'm curious then I've found this on stackoverflow: the approach is to calculate first transposed column, then shift by one column and calculate the transpose of that new matrix.
This was one of the first solutions I've thought but I haven't realized it because I'm too lazy to create a rule for calculating the shifted matrix.

My approach is iterative thus less intuitive:
trans(M1, M2) :- trans2(M1, M1, [], M2, 0), !.

trans2([A|_], _, _, [], N) :- length(A, N).
trans2(M, [], H1, [H1|R1], N) :- N1 is N+1, trans2(M, M, [], R1, N1).
trans2(M, [H|R], L, [H1|R1], N) :- nth0(N, H, X),
append(L, [X], L1), trans2(M, R, L1, [H1|R1], N).

Ok, apart the fact that I haven't got the time to beautify it, the code will iterate columns and for each column it calculates a row of the transposed matrix (yes, exactly what you expect a transpose method to do :P). The key is "passing" around the nth column we're looking at.
After we finish calculating a row, we restart from the first row but looking at the nth+1 column. Recursion ends when there are no more resulting rows, i.e. when we reached the end of the columns.

Wednesday, February 09, 2011

Bluetooth simple one-line device connection pairing with Bluez

Hello,
I've written a simple Python script using the Bluez (version 4.66) stack (thanks to http://shr-project.org/trac/wiki/Using) with this usage:

python connect.py MACADDRESS PIN MOUNTPOINT

Snippet code for connect.py is here. If the device is paired, it will be removed and unmounted.

Disconnection is as easy with:

python disconnect.py MACADDRESS MOUNTPOINT

Snippet code for disconnect.py is here.

Feel free to use the code also for other services, in this case my primary concern was to mount the file system.

Rubik's Cube 3D Game in Vala/Clutter

Hello,
I've written a simple program for playing with a Rubik's Cube using Vala and Clutter.

It features:
  • high simplicity in rotating cube slices and rotating the cube itself in a very natural manner
  • shuffle the cube
  • autosave the game

Download and more usage information at the homepage... have fun :)

Friday, January 14, 2011

Base64 and Quoted-Printable GConverters for GMua

Hello,
lately I'm writing GMua for educational purposes and for evaluating Vala, whose purpose is to simplify writing Mail User Agents or simple scripts, ala Java Mail.
It currently parses IMAP (not yet complete) and has a graphical interface called Gutt (yes, inspired by Mutt) for testing.
In order to parse MIME parts with base64 or quopri content-transfer-encoding I chose to implement a couple of GConverter (will use GMime a day, maybe when they switch to gio, not yet needed) in Vala that you can find here:
I'm pretty sure there are bugs in these converters, by the way I wanted to share them :)

Sunday, December 19, 2010

Valag 1.1 released, graph generator for the Vala AST

Hello,
a new version of Valag, a graphviz generator for the Vala language AST, has been released.

Changes since 1.0 version:
  • Add --format and --prefix options.
  • Update to latest libvala-0.12.
  • Bug fixes.
This new version also distributes the xdot.py program as a viewer for the generated graphs.

More information and download at the Valag homepage.

Friday, December 17, 2010

Maja - The Vala to Javascript compiler

Hello,
I've just released the first version of Maja, the Vala to Javascript compiler. The mapping is not quite complete but you can do pretty much everything you could do with javascript directly. There are (still incomplete) bindings for the qooxdoo framework and the demo browser is being ported to vala successfully.
Maja can be used in any environments, not only web browsers.
Programming in Vala saves you from lots of type safety troubles (Javascript), lot of typing (Java) and the syntax is really enjoyable as it is quite close to the Javascript model.

Usage and download at the homepage.

Wednesday, September 15, 2010

DuckDuckGo search engine

Hello,
in this post I'd like to hint you a very nice search engine: DuckDuckGo. I've been pointed out to this by a post here on why both Google and Yahoo suck (and why Google search does more).
In older posts of mine you can find some examples on how Google search can miserably fail a search.
The main problem with the two approaches is: Google (and Bing too) sorts by popularity, Yahoo by match. So, what can happen is: Google finds something completely unrelated to what you need, Yahoo is much sensible to the keywords you put.

This DuckDuckGo search engine instead, looks up the search keywords and asks you for the meaning of the words (Yahoo phase), and then sorts it by popularity (Google phase). Especially with web 2.0 and publicity, popularity of web sites loses much more importance over the actual relationship between the meaning of the search and the web page itself.

So, as usual the conclusion is: don't use only one search engine, use multiple ones because implementation matters; don't say people "Google is your friend" because it can happen to be offensive, say instead "use your favourite search engine (YFSE)".

Monday, August 16, 2010

Debian Appreciation Day

Hello,
today is the Debian birthday. For this event a Debian Appreciation Day has been prepared to thank all the Debian organization, all the contributors, developers, teams and everything related to the universal operating system. If you want to thank Debian and make developers feel loved :P here's the page: thanks.debian.net.



Thursday, July 29, 2010

Using Mash with Vala

Hello,
recently Mash has been released. It is a library for reading models in PLY format and creating Clutter actors from them. For reference, Blender is able to export to PLY. It means you can draw your models with Blender and use Clutter as rendering engine.
Clutter is a 3D canvas and animation toolkit while Blender is a 3D modelling suite.

What I've tested so far is porting the Monkey Viewer C example to Vala: code snippet and monkey PLY here.



That is going to be awesome, stay tuned!

Mipsdis MIPS32 disassembler

Hello,
I've written a MIPS32 (Release 2) disassembler for ELF files. It is not a simple disassembler, it's mostly made for reverse engineering proprietary boxes for educational purposes. It has been successfully tested on Vodafone Station which has Broadcom binaries. These boxes don't have a sections table, therefore normal disassemblers don't work. Mipsdis instead will guess the bounds of those sections (most important ones are TEXT and RODATA for strings).

This console program outputs a friendly assembly code, whose each instruction is commented (comments copied directly from the mips specification). It also features labels for branches and symbol resolution for strings, global variables and functions.

More information and downloads here.

Friday, June 18, 2010

Idea duplicated again

Hello,
I'd like to point you to this firefox extension HTTPS Everywhere (June 17th, 2010) and SSLGuard which is also a firefox extension (first released Oct 14th, 2009).

The code of the former extension is a lot more complicated and the result is not always quite the same as SSLGuard. In fact, while they support secure cookies and per-website custom rules, SSLGuard lets you add custom websites to be secured directly from a friendly graphical dialog.

You could even install both of them, apparently they don't conflict.

It's the second time decrew ideas are being duplicated. This happened sometimes ago with SSLtoHTML (ettercap plugin) and sslstrip (standalone application), but they released the code before us. Funny isn't it?

I'm not complaining about anything (I'm not saying "copy", I say "duplicate"), just clearing things out. Of course, better have more choice and more works.