miércoles, 15 de marzo de 2017

Browsing allegro lisp docs inside emacs

While programming, I love to read documentation using helm-dash. I've created quite a few docsets for apps/languages that lacked them in the official repos.

Currently I was using python, common lisp, Picolisp, and Redis, but I felt I was going too often to the franz's Allegro Lisp documentation site.  It's nice and loads fast, but it doesn't provide any useful search.

So I created a dash docset for Franz's Allegro Lisp.  As usual, it's in my github.

And here's a little gif I recorded to see how does it look.

martes, 14 de marzo de 2017

git reflog with dates

reflog is this superhero that only appears when it has to save your ass.

A neat thing about it is that it logs everything you do in a given machine. It works locally, none of the reflog is pushed anywhere, and if you 'git clone', your reflog is empty. But...

For us, that are work are doing very far from BlueGreenDeployments, by doing git pull in a server and reloading (in Common Lisp planet you do hot reloads like a boss), this gives a track of when did pulls happen, and so you can find re-imagine the history of deploys, pulls, deploys, fixes.

It's a suboptimal solution, but given it's for free "don't look a gift horse in the mouth".

As usual in the class of git commands that list info, there are lots of formats and customizations.  For me, a simple "git reflog --pretty=oneline --date=short" does the job. 

domingo, 12 de marzo de 2017

CTMCP finished!

After a big hiatus of 6 months (space for CLtL The  unix programming environment, Object-Oriented Programming in Common LISP
,To mock a mockingbird (part of it) , I continued reading Concepts, Techniques, and Models of Computer Programming.

And it's so good I'm gonna put it next to SICP, GEB, HOP and PAIP (when I get around finishing it).  Here are some highlights:

  • The book covers a huge spectrum of programming techniques, and ponders lots of variants and different ways of achieving different tasks.  It focuses a lot in declarative programming, which comes very natural for extending the model to streams, logic, relational and constraint programming.  
  • The whole book examples are written in Oz/Mozart, which is a multi-paradigm language with a Prolog-ish syntax which seemed quite odd in the beginning but in the end I learned to like.
  • The tone of the book is so unopinionated and so 'formal', that I missed Eva Lu Ator, and Alyssa P. Hacker. 
  • I had a lovely AHA moment when discovering difference lists. Very useful to understand the paradigm shift of Prolog style programming.
  • Concurrency is touched quite heavily, and the explanations on why the different models exist, and when to use what were very useful from a practical perspective.  I loved how they introduced Active Objects.
  • Explanations of 'well known' concepts like recusion, accumulators, mapcar, transducers, closures, and streams are very nice, and made me remember of the times I discovered them for the very first time.  
  • Overall, the book is very readable. Clear style and vocab makes it readable in bed.
  • There's an introduction to Constraint Programming. Which feels like total magic. I guess it deserves reading a whole book on that to know a bit more about it.
Really, if you tried SICP and/or HOP and liked it, this book will provide 940 pages of fun and enlightenment.

Next, I'm reading PoEAA (a bit old and enterprisey but it's Fowler). And I have Beautiful Data (O'Reilly) waiting....

viernes, 10 de febrero de 2017

Zsh global aliases for command chaining

(The motivation for this post is my recent discovery of oilshell, a very promising new shell.  The author has been posting regularly for some time, and he has quite insightful ideas. Some of them I had them too and I didn't know they conformed to some defined concepts (I discovered Bernstein chaining two weeks ago). Whatever.... here it goes, as a way to open more discussion topics)

There's a small zsh trick that is unmatched by any other shell. It's maybe just syntax sugar, but it enables some pretty neat tricks.

The feature is global aliases (or "alias -g").

They are alias substituted anywhere on a line. Global aliases can be used to abbreviate frequently-typed usernames, hostnames, etc.

I think of them as some kind of reader macro, that applies substitutions to strings at read time, so there's no need to substitute a full command by another full command.

alias -g


The simplest case is to make an alias for a bunch of flags for a command you use many times (Also look at zsh globbing to see other examples of 'simple' alias -g).

alias -g GLWEEK=' --since=1.week.ago --author=kidd'

Given this ("git last week"), we can use it in different contexts. In this example, the only useful ones that come to my mind are "git log" and "gitk", but to get the feeling of what it does internally, you can 'echo GLWEEK' and you'll get the flags printed.  It allows for a lot of composability, and Bernstein chaining because everything concatenates and tries to apply.

Piping through


Another way to see it is as a way to Forthify your shell a bit more with pipes. This is how I use the feature the most:

If you make aliases expand to pipes (left, right or both), you can make many unix commands compose in a seamless way. Under the hood, you know that the connexion happens through stdin/stdout, but visually it eliminates most of the clutter.

Let's see some examples:

alias -g T='| tail'
alias -g T1='T -1'
alias -g X='| xclip '
alias -g G='| grep '
alias -g GV='| grep -v '
alias -g DM='| dmenu '

Let's see a few ways we can compose this:

ls -ltr G foo GV bar T1 X
evince $(ls *pdf DM)

With some training, it's very easy to see that this will copy the last file that matches 'foo' but doesn't match 'bar', or it will open the selected pdf file.



There are some commands that do not accept arguments from stdin, but they require them to be as command line arguments. in those cases, one starts doing things like:

mplayer $(ls *(mpg|mp4|avi) DM )

Which works, but it breaks the pipe flow.  For that, we can use xargs (as we saw a few posts ago), and we can use, again, another global alias:

alias -g XA='| xargs '

now we can do "ls *(mpg|mp4|avi) DM XA mplayer" .



Here's an example of a uniq function on steroids. it accepts a field number to uniquify, and the rows do not have to be sorted to work.

function uc () {
    awk -F" " "!_[\$$1]++"

alias -g UC=' | uc '
alias -g P1='| awk "{print \$1}"'

Let's see how to use this one: For the sake of the example, let's pretend we want to know the users that have some process running in my machine.

ps -axuf GV USER UC 1 P1

Of course, this is the same as typing the vanilla commands yourself, but IMO, it makes quite a lot of difference on the experimentation easiness.

There are some more fancy tricks, but we'll leave them for some future post.

The whole point of this is that some features allow for greater composability, and let you build your ad-hoc tools in a much easier way than others.  Oilshell has plans to have '{', '}' and '[', ']' as operators, so you can have block like syntax (maybe the semantics of tcl's quoting would be enough?).  Anyway, it's great that the shell space is active and there are interesting things happening. I'll keep oil in my radar :)

miércoles, 8 de febrero de 2017

Henry G Baker's papers

I was rereading "Out of the tarpit" paper, and by the end of it I noticed they reference a paper from Henry Baker: "Equal rights for functional objects or, the more things change, the more they are the same.". The author's name rang a bell, and I decided to explore a bit more.

So, He's the author of a paper I loved to read 3 months ago or so: Pragmatic Parsing in Common Lisp.

The article is an adaptation of Val Schorre's META-II paper to common lisp, leveraging reader macros to create parsers in very few lines of code.

Reading a bit more, I found this other very enjoyable article: Metacircular Semantics for Common Lisp Special Forms . This one takes the approach of metacircular interpreters to explain the behaviour of some common lisp special forms in terms of other common lisp expressions.  I love the bottom up approach, and reminds me of "git from the bottom up", or CTMCP's explanations of the extensions to the Oz language.

He wrote lots of articles related to Lisp to different degrees, but most of them (the ones I skimmed) are written in a very clear language (no pun intended), and quite fun and enlightening reads.

domingo, 22 de enero de 2017

Autocomplete erc nicks with @ sign (for slack)

 This is a very quick hack for something I've wanted for some time.  I'm using slack through their IRC gateway. That allows me to use erc, yasnippets, bug-reference-mode,  and whatnot.

The few things that annoy me of that interface is that to ping users, in slack you are expected to prepend the nick with an at sign. That makes autocompletion kinda useless because, as this redditor explains , it's a pain in the ass to type the nick, autocomplete, go back, add the @ sign, and move forward.

I haven't found a way to solve this in an elegant way, but as a hack, I could add tihs advice functions that will understand @nick as well as 'nick' when autocompleting.  I'd love to be able to just type the name and the autocompletion framework fill the '@'  sign itself, but I couldn't find it, so I'll try this approach I got so far and see if it works well enough for me.

I hope it's useful for some of you, dear emacslackers :)

sábado, 21 de enero de 2017

using xargs to parallelize command line

Did you know that xargs can spawn multiple processes to execute the commands it gets? It's the poor man's gnu parallel (very poor).

Well, I've been dabbling quite a bit with shell scripts lately and I've come to this balance of using shellscripts for simple (or not so simple) tasks. It's a mix of suckless and Taco Bell programming....

Well, the problem at point was to create many connections to some api endpoints. The endpoints would be serving data in a streamming fashion (think twitter hose).   My idea would be to spawn several curls to a "circular" list of urls.

I thought about wrk (because lua), vegeta or siege, but I'm not sure how they would cope with 'persistent' connections, so I tried my luck with plain curl and bash.

It's funny how you can solve some issues in bash with so few lines of code.  I don't have stats, or anything, but the only thing I wanted, that was to generate traffic can be done in plain simple shellscripting.

Things I learned:

- ${variable:-"default-value"}   is great
- doing arithmetic in bash is next to impossible.
- xargs can spawn multiple processes, and you can control the number, so you can use the number as an upper limit.
- while true + timeout are a very nice combo when you want to generate any kind of 'ticking' or 'movement' on the loop.

Here's the script: