Friday, 30 May 2008

Port forwarding with ssh

Let's just say that I've a box with an sshd listening on port 22, but I want it to accept as well connections on port, for example, 443. There might be many many ways to do it, but one way is to open an ssh tunnel, by running this as root on the said box:

ssh -g -N -f -L 443:localhost:22 user@localhost

-f forks, so the tunnel stays open in the background as long as the box is up. -g allows connections from the outside world. -N is there to avoid executing a command (just forward the port). And -L gives the tunnel specification.

Tuesday, 27 May 2008

Process substitution in bash

I like the process substitution syntax in bash. Since I don't expect everyone to already use it at lengths, a small note on it might be welcomed.

Process substitution connects the input or the output of a process list to a pipe whose other end is connected to the rest of your command line. For example, this will list your files in reverse order:

sort --reverse <(ls)

You'd said, I could have used a good old pipe, as in ls | sort --reverse. Fair enough, but sometimes you want more than one input, or output. That's where process substitution comes to the rescue.

I find this particularly useful with diff(1). I like diff. Don't you like diff? (GNU diff, I mean, the one with -u for unified diffs. It don't mean a thing if it ain't got that switch.) I read unified diffs every morning at breakfast. (I swear it's true.)

So let's see, I want to compare the output of two commands. Let's say I want to compare two perl optrees. (A perl optree is the intermediate form in which perl compiles your program before executing them.) To get a good, but concise, overview of a perl optree, dumped on the standard error stream, my favourite command is:
perl -MO=Concise foo.pl

(I think I'll make myself an alias for that one day.)

Let's say my almost similar programs are in files foo.pl and bar.pl. To get a diff of their optrees, the command will then be:
diff -u <(perl -MO=Concise foo.pl 2>&1) <(perl -MO=Concise bar.pl 2>&1)

(Note that I redirected stderr to stdout.) Et voilà.

And if that's too much typing, there's always history substitution:
perl -MO=Concise foo.pl 2>&1
diff -u <(!!) <(!!:s/foo/bar/)

Monday, 26 May 2008

On Naples and its garbage

The situation of garbage disposal in Naples and the monopoly that Camorra (the Napolitan Mafia) acquired upon it is an application of the formula:

mafia = capitalism - state

What happened there? A couple of decades ago, the Camorra began to invest in garbage disposal companies. Garbage disposal and its treatment are quite expensive, especially when the laws require not to dump dangerous chemicals anywhere in the fields or the rivers. But if you don't care about polluting an entire country, garbage disposal, at the market prices, is very lucrative, because it allows for enormous margins. Using intimidation and corruption to wipe out local competition, and selling its services to industrials to cheaply dispose of their waste, (thus gaining approval from the powerful industry bosses), the Camorra has now transformed the Campania in a wasteland where people are a lot more likely to develop cancers than in other parts of Italy.

Fair competition is part of capitalism, but without an effective judicial power to prevent violence against competitors, the game is biased. Moreover, without a government to edict and guarantee safeguards, protecting its citizens from whatever consequences unrestrained capitalism might have on the environment or on the society, ecological and social catastrophes are bound to happen -- at the very profit of the bad ones.

My formula of course applies as well to the Sicilian Mafia, born at the end of the XIXth century around Palermo; at that time, it took advantage of a very good economical situation in Sicily and of a default of government, Italy being a young kingdom, and Sicily just out of feudalism.

Thus, every time I read on the internets anarcho-capitalism, I mentally translate it into Mafia rule waiting to happen. I'm sure the Honoured Society would be happy to see a libertarian elected in the White House, even if this libertarian is the most honest man on earth. (The Mafia doesn't have political opinions -- it helps whoever will help it.)

(As an aside, Tony Soprano comes from a Napolitan family, and officially works in garbage disposal. The writers were documented...)

Friday, 9 May 2008

Why People Are Passionate About Perl

brian d foy asks why people are passionate about Perl. So, brian, here are a pumpking's answers to your questions.

The person who introduced me to Perl showed me that I could throw away all those fragile sed and awk scripts and get the job done much quickier. So that gets us to the second question:

I first starting using Perl to process very large data files. Or at least they were considered very large at the time: less than 2 Go, I think. But I quickly grasped the thing and began to wrote small scripts to automate various things on my computer (and others').

I kept using Perl because it was fun. And it still is.

I can't stop thinking about Perl because... they won't let me! If I stop thinking about Perl, I know they're out there to get me, lurking in the dark corners of the intarweb, with their bug reports, their suggestions and their patches.

I'm still using Perl because, well, basically, because I'm paid for it. But on the other hand, I chose a job where I was getting paid to use Perl. I could have chosen a Java, a C, or (my goodness) a PHP job. But with a proper Perl job you have the CPAN at hand, ready to be used. So you can concentrate with the problem solving and the business side of your applications, because almost all the libraries you'll need are already there.

I get other people to use Perl by hitting them on the head with a -- no wait. Actually that's the most interesting question. I get other people to use Perl by trying to make Perl a less annoying language, in my own scale.

I also program in C, but mostly when I have to patch perl itself -- the only place where you can't use Perl.

Tuesday, 25 March 2008

IRC thought of the day

On freenode, every IRC channel is the zoo of another one.

La maison des girafes

Thursday, 20 March 2008

Google charts on Flickr

Looks like the Google Chart API now does maps. I like maps.

I figured that I could map some of my flickr tags to a map, just to see where I've taken my photos. Here are some of my location-related tags, and the current number of photos tagged with:

amsterdam40
birmingham19
brussels9
venice79
nice70
paris274
lyon60
(total for France tags)404

It's then almost trivial to come up with an image URL from google:

Neat, huh?

But where to go from there? Obviously, it would be a good idea to tag photos with the two-letter ISO country name, maybe as "country:FR" or "country:NL" (not sure what a good convention would be); then, the associated number of photos could be retrieved effortlessly via the Flickr API. Alternatively, if one wants to construct a nice mashup, having a DB full of city names or/and using geotags would be a nice idea too. Tuits anyone?

Wednesday, 19 March 2008

CPAN reports colors

search.cpan.org has, on each distribution page, a link to CPAN testers reports, and, thanks to Slaven Rezic, to matrices that neatly summarize the report statuses per distribution or per author (here's an example for Safe 2.15).

Unfortunately, the default color scheme isn't really readable for color-blind people. However, Slaven used a less known feature of CSS to provide an alternate colouring scheme. In Firefox, when viewing the matrix page, select View > Page Style > High Contrast to get the alternate CSS, et voilà, the colours are now accessible. Thanks Slaven!

Tuesday, 18 March 2008

Harry Connick Jr, the pianist

Keyboard, stripes I recently discovered the pianist side of Harry Connick Jr, who is best known as a crooner. The influence of Thelonious Monk is remarkably high. Broken rhythms, weird block chords, minimalist improvisations: we are in presence of one of the only disciples of The Sphere. He even grabs full codas from Monk. For evidence, listen to One Last Pitch, a trio recording.

And what's remarkable, is that it seems that this influence has been completely overlooked by everybody. Connick is a much, much better pianist than singer. And his piano style is certainly not what you'd expect from a white crooner with the look of an Hollywood playboy.

Well, I guess that it's just another confirmation of the old saying, all jazz musicians are underestimated.

Monday, 21 January 2008

vim and Perl 5.10

If you use vim and want it to highlight correctly the new keywords in Perl 5.10, you can just drop the following syntax plugin script as ~/.vim/syntax/perl.vim :

so $VIMRUNTIME/syntax/perl.vim
syn keyword perlStatementStorage state
syn keyword perlStatementFiledesc say
if exists("perl_fold") && exists("perl_fold_blocks")
syn match perlConditional "\<given\>"
syn match perlConditional "\<when\>"
syn match perlConditional "\<default\>"
syn match perlRepeat "\<break\>"
else
syn keyword perlConditional given when default
syn keyword perlRepeat break
endif
if exists("perl_fold")
syn match perlControl "\<BEGIN\|CHECK\|INIT\|END\|UNITCHECK\>" contained
else
syn keyword perlControl BEGIN END CHECK INIT UNITCHECK
endif

An extension, not implemented here, could be to add a new highlight class for the new regexp verbs (MARK, SKIP, COMMIT, etc.)