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 . 

miércoles, 17 de mayo de 2017

Descarregar programes de RAC1 desde la linea de comandes

Fa anys que sóc seguidor de "La Competència", i no sempre puc escoltarla en directe. Bé, hi ha la opcio de descarregar programes desde "rac1 a la carta".


El tema es que es un conyàs anar manualment a la web i descarregar el mp3. Fins aquesta setmana, el següent zsh script m'ha deixat descarregar el mp3 del dia:

function lacomp () {
    typeset -A days
    days[Sun]=Diumenge
    days[dom]=Diumenge
    days[Mon]=Dilluns
    days[lun]=Dilluns
    days[Tue]=Dimarts
    days[mar]=Dimarts
    days[Wed]=Dimecres
    days[mié]=Dimecres
    days[Thu]=Dijous
    days[jue]=Dijous
    days[Fri]=Divendres
    days[vie]=Divendres
    days[Sat]=Dissabte
    days[sab]=Dissabte
    #echo $(${days[$(date +%a)]})
    echo $(date +%a)
    wget "http://www.racalacarta.com/download.php?file=download.php-file=$(date +%m)$(date +%d)%2012h%20(${days[$(date +%a)]}%20$(date +%d-%m-%y))%20%20%20LA%20COMPETENCIA.mp3"
    return
    }

Doncs ara resulta que han canviat la web, i m'he hagut de fer un altre script per a descarregar l'últim programa de la competencia

function lacompeti () {
    curl http://www.rac1.cat/a-la-carta/la-competencia | pup 'a.fa-arrow-down attr{href} ' | head -1 | xargs wget
    ls -tr *mp3*download | tail -1 | xargs mplayer
}

jueves, 11 de mayo de 2017

Git 2.13 has been released

As you can see in github blog, there's a new git version (2.13).

There are some internal and some external changes, but the one that stroke me as most useful for me is conditional configurations.

Conditional includes, means that you can preset in your ~/.gitconfig some conditions, like

[includeIf "gitdir:~/work/"]
  path = .gitconfig-work
[includeIf "gitdir:~/play/"]
  path = .gitconfig-play
 
Now you can put whatever options you want into those files:

$ cat ~/.gitconfig-work
[user]
name = Serious Q. Programmer
email = serious.programmer@business.example.com

$ cat ~/.gitconfig-play
[user]
name = Random J. Hacker
email = rmsfan1979@example.com  

After that, you'll be able to commit away in any project in your computer, and git will do The Proper Thing.  This is just awesome, that all the hackery I had to simulate this can now go away.  I'm going to add this to my configs NOW. :)


As this is a git post, I'll take the opportunity to mention this blogpost about filter branch. Also, this one about packfiles. Both are advanced topics, but you know..... it's fun :)