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'";
    done
}

aliasgen


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!

jueves, 25 de septiembre de 2014

Back to the trenches with... speadsheets?

I'm back to reality after my craziest holidays ever. Great new people, and fun with old friends...

And I'm back with some research on spreadsheets.  My new role as team leader involves some team organization and managing skills.  Due to my inability to organize myself, I'm trying to solve this once for all, and it's also a good oportunity to take another look at org-mode.

I've been dabbling with org-agenda and appointments. The git repo has already some '.org' files :).

So today I was watching a few talks from the StrangeLoop 2014, and I stumbled upon this 'Spreadsheets for developers' talk.  The talk has its points. I don't agree with everything that is said there but it does confirm the overally idea I already had of spreadsheets.  Everyone uses them to solve their own problems. It's the emacs of non-developers.

So I remembered org-spreadsheet, and hacked a bit with it.  It's really impressive, and, although a bit cumbersome in the beginning, I think it has lots of potential. And if spreadsheets are code, org-spreadsheet is more code than excel


There are many many different shortcuts but you only need a few to get started.

shortcut what it does
c-} toggles column/row legend
c-' global formula editor
c-` cell editor (formulas)
c-c c-c (on #tblfm) updates table recalculating
s-RET inserts previous number +1


I really encourage you to read the manual and also the tutorial, where you'll find out how to write formulas with Calc or elisp.


Also a nice trick is the org-table-to-lisp function, that will parse the table the cursor is on and give you a list of lists with the data.

martes, 1 de julio de 2014

More JIT and luajit links

Here's another of these list of links post: About JIT and Luajit.

This is hardcore stuff. I've read all the articles but honestly, I barely get what I'd have to do to write something with this on my own. Anyway...

The luapower site is full of nice tricks for lua libraries. Highly recommended (at least skim it). Specially the design of glue and lua&luajit tricks.

edit: Also, a brainfuck compiler using dynasm
Cya!

miércoles, 21 de mayo de 2014

multiple value return in lua

Lua functions can return multiple values, and the language will natively assign them to the variables on the other side of the equal sign.

local a, b = (function() return 1,2 end)()
print(a,b) => 1     2
That's fine, but when things get a bit more tricky is when the values are not returned in tail call position.
local a, b = (function()
               local res = (function() return 1 , 2 end)()
               return res
             end)()
print(a, b) =>  1    nil
The catch is that lua assigns the 'rest' of the values only to the last element of tables, or argument lists. If we want to wrap a function into another while not being in tail position, we have to use a little trick. This trick is unpack.
local a, b = (function()
               local res = {(function() return 1 , 2 end)()}
               return unpack(res)
             end)()
print(a, b) =>  1    2

jueves, 8 de mayo de 2014

Presenting Eva

I've hacked a tiny little lisp interpreter in lua, and I called Eva, for obvious reasons.

It's not pretty, it's not complete at all. Hell, it doesn't even have strings, you can't call native lua functions, and there are no conses (although you could get them using functions for that).

The whole point of it was to have some fun implementing a tiny lisp-like thingie, and to make it in lua, which is a language that I like quite a lot (although some of its table missfeatures make me cry sometimes)

Without further ado, Eva .

miércoles, 7 de mayo de 2014

erc makes you faster at jokes!

Hi, today's post is a simple sinppet I wrote to ease the pain of looking for recurrent references on the internet.

At work we use IRC heavily (it's our main channel for comunication). As you know,every platform or channel of comunication has its own processes and joke (slightly related (but interesting nonetheless): The medium is the Massage ) . So IRC is mostly about sending links to gifs and to funny images, and funny images with captions in them.

It's so simple that it doesn't even need explanation. You just have to know that all defuns named "erc-cmd-SOMETHING" will be automatically callable from erc as a /something.



(defun erc-cmd-MEME (wat)
  "Fetch links from the alist of knowledge"
  (let ((h '(("trap" "http://4.bp.blogspot.com/-ae1ZRrrjs8c/Th0rz7ZvogI/AAAAAAAAANU/QM2WW-LNZXY/s1600/original.jpg"))))
    (erc-send-message (cadr (assoc wat h)))))

Combined with erc-image.el, it makes a really nice IRC experience :)