...soul, as in software?

Rantings about life.

Sat, 17 Aug 2013

Funny Shell trick

While sorting out a debian .bashrc file, I came across to this construct:

export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups

I found interesting the ${HISTCONTROL+,} construct, which will evaluate to a comma (,) if HISTCONTROL is defined, to the empty string otherwise (I checked).

It is useful to enrich (i.e., add while preserving the previous values) variables with new values that must be comma-separated.

I'll try to explain this further.

Let's assume that we have an enviroment variable (FOO) that controls the behaviour of some program. We want to make sure that the FOO var holds the value 'bar', but we don't know if some other scriptlet in the chain has already set some other value(s) to this var. So, in order to preserve possibe preset values for FOO, we do this:

[1]: export FOO=${FOO}${FOO+,}myfoo

There are two obvious cases:

a) FOO wasn't previously set, hence FOO=myfoo after [1] is executed

b) FOO was previously set with, say FOO=bar,baz. Then, after [1] is executed, FOO will be FOO=bar,baz,myfoo. Note the comma between baz and myfoo. That's the doing of ${FOO+,}.

posted at: 18:17 | path: | permanent link to this entry

Sun, 31 Mar 2013

fork explained Star Wars style, in Perl


use Force qw(-midiclorians -jarjar);

my $vader = fork;
noooooo()
    unless $vader;  # I am your father

sub noooooo {
    hang_there_for_a_while();
    exit;           # to the Millenium Falcon
}

posted at: 08:32 | path: | permanent link to this entry

Mon, 30 May 2011

Links on Git Workflows

http://nvie.com/posts/a-successful-git-branching-model/

http://jeffkreeftmeijer.com/2010/why-arent-you-using-git-flow/

http://www.slideshare.net/sergio.gil/a-git-workflow

http://codicesoftware.blogspot.com/2010/11/linus-on-branching.html

posted at: 05:54 | path: | permanent link to this entry

Thu, 31 Dec 2009

How to keep a copy of what you watch online.

Adobe Flash (sic) is so pervasive these days, specially for online video distribution.

Sometimes (e.g., TED.com) the site kindly provides you with a link to download the video stream, but more often than not, they don't (e.g., YouTube).

There are some tools around which will download the video feed for you, but only work for certain well-known sites. I'm thinking of course of clive and youtube-dl. These tools work by reverse-engineering the protocol the Flash client use to talk to the "mothership". Sometimes that protocol changes, without notice, and that leaves you out in the cold 'till the tool author cracks it again, and updates the tool in question accordingly.

So, in case you don't have a working tool to download some nice video you just watched, here is a simple procedure to find out the download URL that the Flash client uses internally. Install some logging proxy, such as tinyproxy, and configure your browser to use it. Load the page, watch a bit of the video, and then check the logs. The URL will be there. Feed it to wget, and you are all set!

Note that some sites will put the download URL literally in the web page, as a parameter to the Flash player object, so looking for the string '.flv' on the sources will work as well. RTVE is one of such sites.

This procedure worked for me nicely, and I guess that some variation of it is what the authors of clive and youtube-dl use to crack the protocols. Then I run into citywire, a british financial news site. Their Flash client uses https plus some kind of certificate to connect to their video repository, so the proxy technique won't work. This is because the proxy only gets to see the encrypted connection, so you cannot extract the URL from it. And the certificate precludes the use of faking https proxies like WebScarab Mmmm. This is gonna be tough.

Then I realised (while sleeping, actually) that the design of the client would require securing temporary disk storage to ensure the video reproduction, as the video streams could grow very large, and keeping all that stuff in RAM would be excessive. Where? Well, in /tmp, of course! Yeah, you will find that most Flash video player implementations work that way, securing a file named something like /tmp/Flash7oo3ar, where they download the video stream, and keep it there until you kill the player. Yay!

If you are in Windoze, these clients use exclusive file access to that temporary file, so you cannot copy it. And since the client removes it when it dies (when you close the web page on your browser), not much of a loophole there. But in UNIX® it's a different story. A simple cp or ln to that file will allow you to keep it after the client dies. And what about Mac OS X? There you have per-user /tmp's, but once you locate that directory you will find the aforementioned file there. So we are all good! From now on, if you just watched an online video you want to keep, go to /tmp and it will be sitting there for you to back it up.

I really look forward to the next generation of web browsers providing unified video reproduction capabilities, and hence rendering all this crappy Flash stuff obsolete. That would be the day.

posted at: 11:22 | path: | permanent link to this entry

Mon, 05 Oct 2009

Kids, don't try this at home!

Look at this beauty:

(){ :|:& };:

If fed to bash, it will start a cascade of processes that will leave your box almost inoperable. It is an example of what's called "fork bomb". Look there for further discussion, including cure and prevention.

I really love the Perl version of it:

fork while fork

he he.

Thanks to my friend Dato for showing it to me!

posted at: 15:45 | path: | permanent link to this entry

Tue, 22 Sep 2009

Introduction to Kerberos.

My friend agi referred me to this teatrical introduction to the Kerberos network authentication protocol: Designing an Authentication System: a Dialogue in Four Scenes

The play portraits two sysadmins working at MIT, Athena and Euripides, who decide to take on the task of designing such a beast.

Really nice reading. Anyone willing to play it?

posted at: 17:19 | path: | permanent link to this entry

Thu, 30 Jul 2009

Where was I?

UNIX® shells maintain the previous working directory in the variable OLDPWD, so it is easy to jump back to where you were previously dwelling:

$ cd $OLDPWD

This is a bit cumbersome to type, so this shortcut is provided:

$ cd -

(My then-classmate Carlos told me about this back in '98).

Recently I learned that for commands other than 'cd', which is internal to the shell, ksh and bash provide a tilde expansion for this OLDPWD var, i.e.: ~-

$ cd /srv/media/doc/science/cs/biblia/oreilly/lang/perl
$ ls mastering*
mastering_perl.pdf
$ cd /this/other/place 
$ cp -a ~-/mastering_perl.pdf .    # et voilà !

posted at: 16:50 | path: | permanent link to this entry

Tue, 30 Jun 2009

Music in the park.

I just came home after a long walk through a park nearby (el Retiro). At a certain point, I started to hear an accordion melody, which I happened to know: « La Valse des monstres » from the Amelie original soundtrack, by Yann Tiersen. This would be no more than a nicety, if it wasn't for the fact that the guy who was playing the melody was also... riding a monocycle! :-O. Some circus guy, I guess. I really enjoyed the moment.

posted at: 21:26 | path: | permanent link to this entry

Sat, 20 Jun 2009

Catalyst on Windows

After installing Strawberry Perl run these commands, and may the Gods of ADSL be with you...
C:\> cpanp "s conf prereqs 1; s save"
C:\> cpanp "s selfupdate all"
C:\> cpanp i Win32::Process Catalyst::Devel

posted at: 14:33 | path: | permanent link to this entry

Wed, 22 Apr 2009

Getting X to work on an asus eeebox.

Make sure that xorg.conf looks like this:

Section "Device"
    Identifier  "Configured Video Device"
    Option      "monitor-LVDS"  "LVDS"
EndSection

Section "Monitor"
    Identifier  "LVDS"
    Option      "Ignore"    "True"
EndSection

Otherwise, the output will go to the LVDS port, which is not used on the eeebox.

Found the answer here.

posted at: 08:23 | path: | permanent link to this entry

Thu, 12 Mar 2009

New url for this blog's feed - please update your syndication!

I've reconfigured my site to serve this blog from a static tree, instead of through cgi. The new syndication url is now:

http://blog.pancho.name/index.atom

Please, update your agregator settings to fetch the new url instead of the old one.

I will REMOVE access to the old one in a few days. Thanks!

posted at: 05:25 | path: | permanent link to this entry

Sat, 07 Mar 2009

Inspiration

I just found a reference to this article by Peter Norvig: Teach Yourself Programming in Ten Years

Recommended reading.

posted at: 10:38 | path: | permanent link to this entry

Fri, 10 Oct 2008

Perl mojo.

I enjoy writing small Perl scripts to perform admin tasks. A couple of days ago I had to delete more than 3000 messages in an email inbox, relaying only on POP3 to do it.

Issuing 3000+ dele commands by hand was not a very desirable prospect, so I performed a CPAN search looking for POP3-handling modules.

Bingo! Mail::Box::POP3 does the trick nicely. And it was already installed in my debian box, so I could proceed immediately:

pop3purger
#!/usr/bin/perl

use 5.010;
use warnings;
use strict;

use Mail::Box::POP3;

my $pop = Mail::Box::POP3->new(
	access => 'rw',
	trace => 'DEBUG',
	type => 'pop3',
	username => 'someuser',
	password => 'somepass',
	server_name => 'pop3.whatever.server.example'
) or die "Cannot connect: $!";

$_->delete for $pop->messages;

Once $pop is created, the connexion is stablished with the server, and the message list (headers only) is loaded into the object, and available through the 'messages' method.

A simple 'for' iterates through the list, and deletes every sucker.

Nice and sweet.

posted at: 07:33 | path: | permanent link to this entry

Wed, 19 Mar 2008

Clarke is gone.

This morning I started my day watching the 9th episode of "The Bing Bang Theory". Just the first minutes, since I had to go to work. It was hilarious, they even made a funny homage to '2001 - a space odyssey movie' (can you believe it?). Feeling comforted by it, I went for my daily dose of slashdot, and then it struck me:

Arthur C. Clarke is dead at 90.

My favourite writer is gone. He will meet Asimov in /dev/null, and make the place more fun!

Fare well, dear Sir.

posted at: 08:23 | path: | permanent link to this entry

Mon, 21 Jan 2008

Dinosaurs in Madrid!

A couple of weeks ago I was taking a pleasant walk by the neighbourhood when... GaLAxY! a Tyrannosaurus rex! Well, not quite, but at least a well preserved craneum from one of them. It was no museum, no... A shop! It is named "Geoda", and specialices in fossils and minerals. Must see!

GEODA
cl. General Díaz Porlier, 19
<M> Goya
Madrid
SPAIN

posted at: 14:03 | path: | permanent link to this entry

Tue, 15 Jan 2008

On ssh-agent

Yesterday a friend had an issue with ssh, so after having my dose of sleep, I decided to write about it and share it with the World! :-)
The Problem

If you use ssh, you probably have found an use for RSA/DSA keys. With these, instead of having to type (and send) passwords when you connect to a remote host, you just connect! (more on that later).

But unless your private key is saved unprotected (i.e., without a passphrase) each time you establish a ssh link you will have to type that passphrase. Not much of a gain, right?

But fear not, fellow hackers. ssh-agent to the rescue! This beast will keep an unencrypted copy of our RSA/DSA keys in memory, and to do so we will only have to type the passphrase just once (per session)!

You can even use svn or CVS over ssh, without a hassle.

Now, how does ssh know of the existence of ssh-agent? Well, this is UN*X, right? So, through the environment.

When invoked, ssh will look for this variable in the environment:

SSH_AUTH_SOCK=/tmp/ssh-lyKDh18679/agent.18679

So, if this one is set, ssh will try to talk to ssh-agent by means of that socket, and ask for her help to autenticate. This will initiate a Diffie-Hellman handshake, but that's another story...

Chicken and Egg Problem

When invoked, ssh-agent will become a daemon and provide the following output:

$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-BepcqN5028/agent.5028; export SSH_AUTH_SOCK;
SSH_AGENT_PID=5029; export SSH_AGENT_PID;
echo Agent pid 5029;

So, as of now, if we do nothing more, we well have a ssh-agent running, and nobody will know about it, not even ssh!

We have to affect the environment for everybody to know that we have an agent running, and how to contact it.

But the output of ssh-agent, if properly handed, would do just that!

$ eval `ssh-agent`
Agent pid 5029

Hey, now our environment contains SSH_* variables, that will be inherited by any subshell or subprocess. Including ssh!

If we use our system through a single point of entry, e.g., a single tty, then this setup works for us. But if you use either multiple ttys or a graphical environment with multiple terminal windows, then you have a problem. In these last two scenarios, if you launch a ssh-agent in a terminal, that daemon will not be known in a sibling terminal, so to say. Because there is no way that one process inherits the environment from a sibling process.

If you have to deal with the multiple ttys scenario I recommend the use of 'keychain'. You will have to tweak a bit your .profile rc files, but otherwise works like a charm. It is a simple wrapper over ssh-agent. RTFM for more on that. (n.b.: F stands for Fine).

Now let's check the multiple (graphical) terminals scenario. I'm talking about rxvt, or xterm, or similar. Well, fortunately, the problem was solved may years ago. The X Window init scripts spawn a ssh-agent for us (if configured to do so), so every shell or process we get in our session is the descendant of an 'enlightened' one, i.e., one who got its environment updated to include the SSH_* variables. So we got it! We can right now launch a terminal and type:

$ ssh-add

And dutifully type our passphrase.

Even more, if we use this feature frequently, we can arrange our .xsession to ask for our passphrase just after login.

Sample .xsession:

SSH_ASKPASS=/usr/bin/ssh-askpass ssh-add < /dev/null
exec x-window-manager

This invocation of ssh-add is a little fancy, right? If we install the ssh-askpass software (debian package: ssh-askpass), we can tell ssh-add to use it (via environment) as a means to get the passphrase from us. Otherwise, ssh-add would try to read it from the terminal, which is not connected to the screen/keyboard in this phase of the session setup.

Well, hope that it helps! Feedback always welcome!

posted at: 07:45 | path: | permanent link to this entry

Fri, 04 May 2007

Bye bye, pesetas!

Hoy he ido al Banco de España, a cambiar mis últimas pesetas. Nunca había estado dentro, aunque una vez ví el interior en una película española, con José Coronado (sic).

Me gustó mucho verlo con mis propios ojos, y también fue curioso el proceso de canje; en cierta ventanilla disponen de una máquina donde se echan las monedas, y automáticamente se clasifican y contabilizan, de manera casi instantánea.

Bye bye, pesetas!

posted at: 09:49 | path: | permanent link to this entry

Thu, 26 Apr 2007

La Huella de Bach.

Thanks to my friend ANTONIVS, I attended a nice concert today. I enjoyed it thorougly, except perhaps Hindemith's quartet #5 op. 32, which failed to capture my enthusiasm... :-)

The last piece of the concert read like this in the booklet:

«Obertura de El holandés errante tal como la tocaría a primera vista una mala orquestina de balneario a las siete de la mañana junto al manantial»

I don't feel very much like translating that one; perhaps one day I will...

It was hilarious! They played very much like they said! Apart from 'Les Luthiers', this is the first time I've ever laughed with classical music.

posted at: 20:00 | path: | permanent link to this entry

Valid XHTML 1.1 Valid CSS! powered by blosxom Debian GNU/Linux VPS hosting by RimuHosting