martes, 27 de junio de 2017

Articles on transducers

Some time ago I wrote about recusion and the Y combinator. It is a nice mind puzzle to try to understand all those constructions and techniques. I also linked to a recursion-to-iteration series that was very deep in the subject.

Today, I'm comming with a copule of links to recusion, but also transducers .

If you haven't had enough, another great Eli's post about computed gotos.  It talks about how gotos are faster than a switch-case statement for a tight dispatch table. Aaron Patterson has a great talk about things like this at a higher level called something like "what's in a method" or something like this. Google it for more info.

lunes, 19 de junio de 2017

TIL: evil-buffer-regexps

So I have my evil-mode perfectly adapted to my workflow, activating or deactivating it by default depending on the major-mode, so that I don't get into normal mode on magit buffers, or sly-*, or eww.

BUT, there are some buffers which you cannot easily control, because they reuse some major mode where I usually want evil-normal, but not in those cases.

In my case, it's *sly-macroexpansion* and *sly-description* buffers. They are both "lisp-mode" buffers (for syntax highlighting purposes and such), but I want 'q' to quit them.   As they do not represent any file, I was out of luck binding modes to file extensions. (btw, here's some recent article talking bout the ways emacs chooses your major mode)

So trying to hack something using emacs hooks, I found that, in fact, evil has us covered, and provides a evil-buffer-regexps, that allows us to predefine modes on given buffer names.


(add-to-list 'evil-buffer-regexps
             '("\\*sly-macroexpansion\\*" . emacs))

miércoles, 14 de junio de 2017

Visualisation, patterns, and perspecives

This all started a couple of weeks ago in the J on the Beach conference, where I was in a talk by Santiago Ortiz, which was VERY inspirational to me.

He was talking about the infinite forms of visualizing information (with nice examples about "ways to represent the concept 75". It might seem a very stupid exercise, but it was very interesting to see way many more representations that I was expecting to see.)

Days passed, and I kept thinking about visualization of stuff via alternative and non usual ways. The fact that I'm reading "The Mind's I"(Hofstadter & Dennet) helped to keep thinking about Alan Kay, Seymour Papert, Douglas Hofstadter, who in one way or another they always look at things in ways that are different to what a normal layman would look at them, and they make connections at a cognitive level that other (we) can only grasp after-fact, and when we are spoon fed.

Something like tihs happened to me on that talk. Concepts that weren't totally alien to me ("a point of  view is worth 80 IQ", creating a callgraph as it executes to learn about memoizing), were made obvious when that guy was explaining them in a very vivid and enthusiastic way. Big kudos.

I've been always a fan of all kind of puzzles, and mind hacks (I still remember that 'Mind Hacks' OReilly book). The talk also had some mnemotechnic tips and tricks. Another +1.

So, fast forward 3 weeks, and I already have this dupplot repo where you can display code duplication as a dotplot. Very nice and handy :).

So today at work, my colleague Carlos passed me this article about using your visual capabilities as a computing engine.  A total mindfuck. check it out.

And this evening I've been looking for David Waltz's interpreting line drawings that I discovered in an excelent talk by Gerald Sussman. This line labeling makes a lot of sense when you think about it, and it's dead easy to get.

I still wanted to talk about smalltalk tools for visualizing and reasoning about code.  And about data ingestion growing linearly, while insight grows discontinuously, because it's from connections between nodes that people understand behaviours andget value from it.

Also, one of the games Santiago Ortiz did was about remembering triplets of (person, action, place) for every number from 0 to 99. Then, when you have to remember say, 6 digits, you group them by chunks of 2, and group those grouped numbers by 3. After that, you may remember a scene that is about the person that refers to the first 2 digits, doing the action of te second 2 digits, in the place ment by the third 2 digits.  Messi exploding the Moon was 104569.  Amazing how these things work so well. :)

Gracias!

lunes, 12 de junio de 2017

Visualizing code duplication as dot plots

 Lately I've been having to deal with some codebase which I suspected
  it had lots of duplicated code.

  My task was actually fix some parts of the application, cleanup the
  some of the parts, and end up owning the code as mine.

  So it was a perfect opportunity for me to give a serious thougth to 

Object Oriented Reengineering Patterns , refactoring, and Working with
  legacy code.  I started with OORP, because it's the less widely
  known about all three, and I thought maybe there would be advice
  that's not widely covered on other places in the internet.

  Among other advices (and related to other works in the smalltalk
  world), there's the thougth about trying to look at the code in
  different ways, not the obvious 'lines of text'.

  So here's dupplot, a small script I wrote to visualize code
  duplication through dotplots.

  While working with dupplot itself, I started pushing lines of code,
  to make it work the first time. And then, I was thinking that I had
  some code duplication (opening the file, normalizing lines,etc.) but
  it was generally ok-ish.

  Just for the sake of testing the program against itself, I ran it, and got this:


  So I thought that I'd try to fix some of the duplication, and yeah,
  now it looks much better.


Much much nicer, no? Both codes are available in https://github.com/kidd/dupplot, as dupplot.pl and dupplot2.pl.

martes, 6 de junio de 2017

scripting your .ssh/config with scheme

Generating config files via programs is an old trick which I'm not going to rediscover now. But this one is my first scheme script I wrote for that purpose.

It's about generating a config file you ought to put in your ~/.ssh/config , so that there are some sane defaults when you are ssh-ing to your servers.



It's using the amazon cli interface to fetch the instances of your aws infrastructure. Then, concatenating it with a list of custome servers, and that's basically it (I'm using chicken scheme here, with the regex module which you can get via chicken-install):

With just this, you can already ssh to the servers and have your username filled in, or have your aliases in there.

Also, as I'm super super lazy, I also have a readily available command to prompt me for the server I want to ssh to, and make it ssh there. Quite simple stuff, but hey, it works :)

urxvt -e ssh $(grep 'host ' .ssh/config | awk '{print $2}' | dmenu -l 10)

jueves, 1 de junio de 2017

TIL: pipe postgres output to console

If you use postgres and want to run a query from the console, and react on the output of the console, here are the flags that will make postgres just output the output of the query, without counts or titles, or anything.

psql -A -q -h host1 -U user1 -d database1 -p 5439 -c  "select count(*) from stv_sessions where user_name = 'usertofind'"  -F, -t |
 grep "^0$" || send-me-a-mail "we detected usertofind"

In this case, we're not using '-F,' but it would make the output be a CSV, so you could do fancier things here.

In this case I want to check if a user has an active session. You can put it in a cronjob and leave it running for some time. 

Yes. there are logs for that .