viernes, 31 de octubre de 2014

Poetry with factor.

I'm at the moment at the polyconf in Poznan. The average level of
the conference was very nice and High quality deliveries.

One of the activities of the conference was a programming poetry challenge.

Given that lately I've been doing some factor, and the huge
flexibility of it, I decided that this would be a competitive
advantage. And it certainly is.  Basically because it uses no syntax
at all, you can just type a text, and make this text do nothing.

And the trick is to rewrite no-word to a nop.  In the end I didn't
make it into the poetry contest (the price was a jetbrains license anyway).

Here's the code. Lovely.

jueves, 16 de octubre de 2014

Metaprogramming Zsh - Poor man's autojump (or J (or Z))

There's autojump, there's also J, there's also Z.... Each one of them with its own fans.
I've been trying some of them on and off, but mostly ditched them because I don't need the complexity and I don't get used to type 'z' when I mean 'cd'.

An easy and smart alternative is to autogenerate aliases on boot. It's easy, you can understand all the logic behind it, and your shell will provide the autocompletion. Pretty darn simple.
function aliasgen() {
    for i in ~/workspace/*(/) ; do
        DIR=$(basename $i) ;
        eval "alias $DIR='cd $i'";


For your usual projects, this should be more than enough. "But, but sometimes I want it more dynamic aliases, like, for random directories", I hear you say. Ok, then there's this nifty functions that also creates aliases on the fly.

function a() { alias $1=cd\ $PWD; }

When you're in a directory you wanna keep for later, type "a foo", and an alias "foo" that will go to the current directory will be generated.
Even if you wanted to persist them you could create a symbolic link from the "~/workspace" directory in the previous snippet with the choosen name.
These 2 little tricks just show how using old tools and some wit can get you going a long distance.
I hope you enjoyed this. Cya next time!

EDIT: Post deprecated in favour of CDPATH .  At least I learnt a new thing . Thanks Toni!