Archive for the ‘Non classé’ Category

support Mercurial sous TextMate

Mercredi, mai 13th, 2009

Un “Bundle” existe sous TextMate (le super éditeur Mac) pour gérer les sources sous mercurial.  La façon simple de l’installer est d’exécuter le script ci-dessous qui proviens d’ici où vous retrouvez aussi une liste de Bundle disponibles.   


 

#!/bin/sh

LC_CTYPE=en_US.UTF-8
SVN=`which svn`

echo Changing to Bundles directory...
mkdir -p /Library/Application\ Support/TextMate/Bundles
cd /Library/Application\ Support/TextMate/Bundles

if [ -d /Library/Application\ Support/TextMate/Bundles/Mercurial.tmbundle ]; then
	echo Mercurial bundle already exists - updating...
	$SVN up "Mercurial.tmbundle"
else
	echo Checking out Mercurial bundle...
	$SVN --username anon --password anon co http://macromates.com/svn/Bundles/trunk/Bundles/Mercurial.tmbundle/
fi

echo Reloading bundles in TextMate...
osascript -e 'tell app "TextMate" to reload bundles'

Hidding content in frontrow

Lundi, mars 16th, 2009


Looking around, I found nothing interesting explaining how to hide content in frontrow.  Why do this?  I don’t want all the items to appear here.  For example, I don’t want my TV Show in ITune to be available in Front Row.

The secret is in the /System/Library/CoreServices/Front Row.app/Contents/PlugIns where reside the information about what is displayed in the main menu.  Juste renaming the  TV.frappliance to .TV.frappliance (adding a dot in front of it) hide this item in the menu.May be we can have more granularity (using the checkbox in front of the item in itune for example) but I haven’t time to test everything.

CVS repository switch

Lundi, mars 9th, 2009

This is a simple script that change recursively the CVS repository of a project.

In this example, it changes from “-d :ext:lsabo:/gen” remote server to a local file repository “-d /cvsroots/gen”.

find * | grep Root | xargs sed -i 's/:ext:lsabo\/gen/\/cvsroots\/gen/'

PDF Half page splitting

Jeudi, février 26th, 2009

I’ve found this interresting script digging around.  As I’ve a lot of old book got scanned 2 / 1 pages and I don’t found then easy to read on my portable device I think this could be useful.

#!/bin/bash
#script:    unpnup
#        This script reformats pdf files where two portait pages
#        are joined on one landscape page (like pnup does). After
#        completion each page is on one single fullframe page
#         Copyright (c) 2007 F5 GmbH
# Author: Harald Hackenberg <hackenberggmx.at>
#
#programs required:
#           pdftk, pdftops, poster, epstopdf
#
#
#
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
# the full text of the license.
if [ “$1″ == “” ] || [ “$1″ == “–help” ]; then
echo
echo “Usage: `basename $0` filename”
echo
else

mkdir tmp
cd tmp
pdftk “$1″ burst
for file in pg*.pdf;
do
pdftops -eps $file
poster -v -pA4 -mA5 -c0% `basename $file .pdf`.eps > `basename $file .pdf`.tps
epstopdf `basename $file .pdf`.tps
done
pdftk pg*.pdf cat output ../`basename $1 .pdf`_unpnuped.pdf
rm *
cd ..
rmdir tmp
fi

Programmation objet

Mardi, novembre 18th, 2008

 Extrait d’une entrevue avec le créateur du langage Erlang.  Il parle de sa vision de la programmation orientée objet.
Ref: http://www.infoq.com/interviews/Erlang-Joe-Armstrong

You’ve been reading my OOP sucks blogs. I saw a blog yesterday, they said Erlang is actually more object oriented, truer to the spirit of pure object orientation than all object oriented languages. You could take two views: you could say either Erlang isn’t object oriented - which I used to say a few years ago - or you could say it’s more object oriented than all the object oriented languages. Alan Kay said that he made a mistake in not really emphasizing the messaging aspect of object oriented programming. He said in SmallTalk you talk about sending a message to an object, but you don’t, you do a function call. I think function calls and remote procedure calls are too high-level in the sense that a function call or a remote procedure call returns to the person who made it.

If I do remote procedure call against you, I can say “Hey, do this!” and the answer automatically comes back to me, but that’s not how we work. I could say “You do that” and reply to this guy. Why am I involved? That’s how we behave. If you are a manager at office you say “Can you check this out? When you’ve done it, tell this guy”. This is just an asynchronous message passing model. I think when you talk about object orientated programming, when you model a world, you are encouraged to think in terms of objects and I don’t see objects. I also have what you would call the categorization problem: which object do I put my code in? Sorry I just don’t get this. Let’s suppose you have a method, in SmallTalk terms, that manipulates time of a directory structure or something like that, is this a subclass of a time object or is it a subclass of a directory object? I don’t know.

Years ago I’ve started several projects staff - file my data/my letters, physical papers and research reports and things like that. Every time I’ve done that it failed, because I get files and I put something on this line - it says “Correspondence”, “Lectures”, “Papers”. Then I get this thing: it’s a paper, I put it in the file called papers; this is a letter which contains a paper “Do I put it in ‘Correspondence’ or do I put it in ‘Lecture notes’?”. It breaks down because I don’t know where to put it. I think if you’ve got objects in your function, which object do you put it in? I made another filing scheme, in which I just numbered everything, and I have files and I go over my office and the first file says 1-167 and the next file says 168- something. I have a single file that goes 1,2,3,4 and some text. I use emacs to create, I use grep to search, and it’s a brilliant system!

This is how we organize things in English. We have a dictionary and when we want to know what the word means, we look it up in the dictionary. Everything is in alphabetical order - that’s a good way to organize data. I think object oriented programming is not a good way to organize data. There is a principle in programming “Never write something twice” - yes, it’s a fine principle, a great principle, but let’s think about this: “How do I find the old stuff, that I am going to reuse?” That becomes extremely difficult, in fact, I think people have been deluded into thinking that this choice is easy. When I started programming, there were no choices, I programmed everything in Fortran - Fortran was the only language I had on my machine. Nowadays, some poor sod’s got to choose the programming language: “Should I have Java or C# or C++ or Lua or F# or Pascal or Prologue or Erlang or Haskell? On what should I do it?” “You don’t want something in the-NET framework or a Java framework that runs on the JVM or on Mac OSX?”

You have all these decisions, incredibly difficult to make, and then you got bosses. You don’t write this stuff in scratch! You got to reuse somebody else’s code. After all that is. Somebody else’s code doesn’t do exactly what you want - it does something that’s subtly different. Then, the time taken to modify and understand this old code takes an incredible amount of time. Have you ever sat there with code that somebody else has written and have to modify it? You spend hours and hours doing it. You can’t reuse object oriented code, because all the stuff it inherited has to be there as well. You can’t just take this stuff out and put it in your program cut and paste, like you did in C, or Erlang or Prologue or Perl, you got to take all the stuff it inherits from.

One of the problems I had with object oriented programming, one guy said: “You wanted a banana but what you got was a gorilla that was holding the banana and the entire jungle. You got a lot of stuff in it and all you wanted was just a little bit of code”. The Lisp idea - lots of little functions - ubiquitous data structures like Lists, everywhere, and lots of very small functions that work on this, that these are highly reusable. Code that’s referentially transparent, that means if you call it twice with the same arguments, you get the same value - it’s very reusable. To them the question is “How do we reorganize all this stuff? I think something like a dictionary, like the English dictionary, put in alphabetical order. Don’t put lots of modules, just put one module! If code is referentially transparent, it’s small functions, then it doesn’t belong to object. Where does it belong? What is the containing object? There isn’t one! So, just put them all in alphabetical order and use Google to search it and you’ll find the code easily.

REST, RESTFull, RESTLess the saga

Lundi, octobre 20th, 2008

Un bon vieux principe élémentaire du web.. un URL c’est supposé être un document.

Du Full REST (et même du rest less) implique donc qu’un URL correspond à 1 document et soit “cachable”.

La nomenclature d’une URL du type

http://”HOST_NAME”/usedcar/fullloadbygeocoordinates?lat=43.345&long=-79.801&dist=250

serait donc fautive.. il faudrait utiliser un format

GET http://…./fullloadbygeocoordinates/43.345,-79.801

pour être plus conforme.

Cependant l’utilisation avec des paramètres pourrait être faite en utilisant préalablement un POST pour créer un document

POST http://”HOST_NAME”/usedcar/fullloadbygeocoordinates?lat=43.345&long=-79.801&dist=250

qui retournerai l’URL d’un nouveau document créé en utilisant les coordonnées en paramètre et par la suite appellé en GET

GET http://….url retourné… ?page=1&encoding=json
Ce nouveau document peut être référé par plusieurs requêtes POST avec plus ou moins de précisions sur les coordonnées, permet de faire varier l’ordre des paramètres, etc.  Ce nouveau document est également référençable et “cachable”.

L’utilisation de l’URL fautive (avec les lon/lat en paramêtre dans la requête GET) devrait au moins retourner une redirection (302) sur un URL correctement forgé avec les coordonnées dans l’URL comme référence au nom du document et non pas en paramètre.

Mac Os X - Barre d’application

Dimanche, septembre 21st, 2008

Saviez-vous qu’on peut retirer facilement des icones de la barre d’application au haut (par défaut) dans Os X?  Il suffit de cliquer dessus en maintenant la touche commande (la pomme) enfoncée et de “dragger” les icones hors de la basse.  C’est de cette manière dont je me suis débarassé de l’icone de “mobile me” que je n’ai jamais demandé de voir apparaître!.L’on peut également de cette manière, réorganiser les icones présentes dans la barre en les déplaçant sur la barre. 

Building PNG Images

Jeudi, septembre 18th, 2008

Did you ever try to build a png image (with a programming language, not an image editor)?  A lot of code sample are available on the internet.  But most if not all are using libpng or some high level libraries like gd.

But what happend if you can’t install libraries on the system where you’re working?  Ever thing about building an image from scratch?  Here is what I do in PHP.

This isn’t the most performant code, but at least it generate a valid PNG image without any non standard libraries.   (Some one could say that zlib or crc are php external libs.. but I haven’t see any php distribution whitout them in a while!)

&lt;?php
/*
* Title: PNG Image Generation
* Author: Jean-Luc Cyr
* Date: 2008-09-17
* License: GNU GPL2
* Description: Generate a simple PNG image
* directly in PHP without using external libs
* like GD.
*/
 
header("content-type: image/png");
 
function long2string($long)
{
$string = chr(($long&amp;0xFF000000)&gt;&gt;24).
chr(($long&amp;0xFF0000)&gt;&gt;16).
chr(($long&amp;0xFF00)&gt;&gt;8).
chr(($long&amp;0xFF)&gt;&gt;0);
return $string;
} // long2string()
function build_png($matrix, $w, $h)
{
////////////////////////////////////////////////////////////////
//PNG Header
$image = chr(0x89).chr(0x50).chr(0x4E).chr(0x47);
$image .= chr(0x0D).chr(0x0A).chr(0x1A).chr(0x0A);
 
////////////////////////////////////////////////////////////////
//Header Chunk
 
//Chunk type
$chunk = "IHDR";
//Chunk data
//Width
$data = long2string($w);
//Height
$data .= long2string($h);
//Depth
$data .= chr(8); //Bits per sample
//Color Type
$data .= chr(2); //RGB
//Compression method
$data .= chr(0);
//Filter method
$data .= chr(0);
//Interlaced method
$data .= chr(0);
 
$crc = crc32($chunk.$data);
//Add length at start
$chunk = long2string(strlen($data)).$chunk.$data;
//Add CRC at the end
//Dump chunk
$chunk = $chunk.long2string($crc);
$image .= $chunk;
 
////////////////////////////////////////////////////////////////
//Data Chunk
 
//Chunk type
$chunk = "IDAT";
//Data (2x2 rgb 8bits)
$s = 3; //samples per pixels
#$matrix  ="\0\0\0\0\0\0\0\0\0";
#$matrix .="\0\0\0\0\0\0\0\0\0";
#$matrix .="\0\0\0\0\0\0\0\0\0";
// No filter so add 0 to beginning of each scan line
$datas = '';
for($c=0; $c&lt;$h; $c++)
$datas .= "\0". substr($matrix,$c*($w*$s),($w*$s));
// Compress Data
#$zdata = gzencode($data,9,FORCE_DEFLATE);
#$zdata = gzdeflate($data,0);
$zdata = gzcompress($datas,0);
// Calculate CRC
$crc = crc32($chunk.$zdata);
// Add length at start
$l = strlen($zdata);
$chunk = long2string($l).$chunk.$zdata;
// Add CRC at the end
$chunk = $chunk.long2string($crc);
$image .= $chunk;
 
////////////////////////////////////////////////////////////////
//End Chunk
 
// Chunk type
$chunk = "IEND";
// Data
$data = "";
// Calculate CRC
$crc = crc32($chunk);
// Add length at start
$chunk = long2string(strlen($data)).$chunk.$data;
// Add CRC at the end
$chunk = $chunk.long2string($crc);
$image .= $chunk;
 
// Send out the image
echo $image;die();
} // build_png()
////////////////////////////////////////////////////////////////
// Demo code
 
// Build a simple image matrix
// 256 x 256 x 8rgb
 
$w=256; // width
$h=256; // height
$s=3;   // 3 x 8 bits samples per pixel (8bits rgb)
for($x=0; $x&lt;$h; $x++)
for($y=0; $y&lt;$w; $y++)
//    for($z=0; $z&lt;$s; $z++) //Ordered R G B
$matrix .=
chr( ( (($y/64)&lt;1) &amp;&amp; (($y/64)&gt;0) )?$x:0 ). // R
chr( ( (($y/64)&lt;2) &amp;&amp; (($y/64)&gt;1) )?$x:0 ). // G
chr( ( (($y/64)&lt;3) &amp;&amp; (($y/64)&gt;2) )?$x:0 ); // B
 
build_png($matrix,$w,$h);
die();
 
////////////////////////////////////////////////////////////////
// Hex dump image for debugging
 
for ($x=0; $x&lt;strlen($image); $x++) {
printf("%02X ",ord($image[$x]));
if ((($x+1)%16)==0)
printf("&lt;br/&gt;");
}

Agile - Scrum

Jeudi, juillet 10th, 2008
Mais qu’est-ce que c’est que ça Agile et Scrum?
Selon WikiPedia:
 

Scrum est une méthode agile pour la gestion de projets.
 

et

La notion de méthode agile se limite actuellement aux méthodes ciblant le développement d’une application informatique. Ces méthodes Agiles permettent de concevoir des logiciels en impliquant au maximum le demandeur (client), ce qui permet une grande réactivité à ses demandes. Les méthodes agiles se veulent plus pragmatiques que les méthodes traditionnelles. Elles visent la satisfaction réelle du besoin du client, et non d’un contrat établi préalablement. La notion de méthode agile est née à travers un Manifeste Agile signé par 17 personnalités.”

J’ai essayer de trouver quelques liens intéressants sur le sujet.

En premier, voici deux podcasts (en anglais) dont l’un avec un des ”inventeurs” du scrum.



Et voici les autres

Il y a également plusieurs volumes intéressants et d’autres liens pertinents.

iPod Touch - Note/GTD Applications

Lundi, mai 19th, 2008

J’ai récemment essayé plusieurs applications.  Particulièrement dans le but de trouver quelque chose qui se rapproche de la méthode GTD pour organiser les tâches à faire.  Parmi mes critères, il devait rouler sur le iPod Touch, mais également se synchroniser avec mon portable et/ou d’autres ordinateurs.  Idéalement la synchronisation pourrait se faire par réseau sans fil (wifi) et non pas avec le cable USB.  De plus, il ne devait pas s’agir d’application web (qui ne fonctionne pas s’il n’y a pas de réseau comme durant l’épicerie). Celle dont je me rappelle:

  •  Todo
  • MobileToDoList
  • ShopList
Finalement j’ai opté (temporairement) pour l’utilisation de l’application native de note (qui ressemble à des petits post-it jaunes) du ipod jumelé avec une application web qui permet de consulter et modifier les notes via une interface web à partir d’autres appareils connectés sur le même réseau sans-fil.
  • RemoteNote
Il y a également plusieurs application web de disponibles mais elle ne répondaient pas à mes critères de base.