lunes, 25 de julio de 2016

git pre-commit blacklist

Here's a simple solution if you want git to not allow you to commit debug messages or blacklisted words.

The nice thing about the snippet is that it only counts added lines, not removed, so you can clean code with this pre-commit active, but never make it worse.


FORBIDDEN='declaim\|break'
git diff --cached | grep '^+' |  grep -n $FORBIDDEN && \
 echo "COMMIT REJECTED Found '$FORBIDDEN' references. Please remove them before commiting" &&\
 exit 1

slack -> jabber -> irc -> erc

Slack can be used though alternative gateways appart from the slack clients themselves.  They offer both jabber and irc gateways that map quite well to slack model.

I had previously used the irc gateway, and erc did the trick with no extra configuration at all. But things changed and now I only have the jabber gateway at my disposal.

The problem is that if you want to use a decent emacs client, you'll have to use bitlbee and end up mapping jabber to irc, so you can use erc/circe/rcirc (which are far better at IRC protocol than jabber.el is at xmpp)



To chat privately other peers it's a matter of /j name-of-the-buddy.  Joining rooms is not as direct, and first you have to create some 'mapping' rooms in your bitblee configuration, before being able to join them.

Whatever, here's how to integrate slack with bitlbee (and with erc)

On bitlbee buffer:
  •  chat add 0 room-name@conference.myserver-foo.xmpp.slack.com
 0 stands for the account number. 'conference' has  to be there. it's a plain string, you don't have to substitute it for anything. replace myserver-foo for your server name. room-name is the name of the chat in slack

  • chat list
This will show you the rooms available

  • /join room-name
Notice no # sign.
  • channel 4 del
4 is the chat you want to remove in case you messed up with something.

And that's it. Now you can slack from erc, and you can use all erc machinery (yes erc-robot, I'm looking at you).




jueves, 21 de julio de 2016

TIL: Embedding strings into strings in bash

In bash there's always quite a lot of quoting to be done when you're embeding commands into commands, and possibly want to interpolate some variables.


To save one quoting, there's the option to use HEREDOCS, and assign a string into a var.

lunes, 18 de julio de 2016

TIL: Remove a defined method (with defmethod) in Common Lisp

I created a defmethod for a more specialized class than the ones existed. and now I'd like to remove that method....

(remove-method #'foo (find-method #'foo '() (mapcar #'find-class '(class-of-first-specializer class-of-second-specializer))))

viernes, 15 de julio de 2016

Simple 'dsls' using strings

I'm currently reading The Unix Programming Environment (1st ed). At some point, the authors show how to make a terser version of ....

 It's not entirely clear when I saw this for the first time, I'd say I saw it in some norvig's python code (which I can't find anymore, if you know what I'm talking about comment please. I've spent too much time searching that code)


He was creating a regex from a string of whitespace separated words. something like this: "|".join(" ".split(words)) .

 I find super nice the fact that one can create abstractions on abstractions, or use data structures as intermediate stepping stones.

We (at least, myself) tend to usually think at one level of indirection. You can think of a Set implemented via an array, a hash, or a Bloom filter, but it's usually "I want the 'set' functionality, so I go and fetch an implementation of that functionality".  In those cases, they use intermediate data structures so that they can manipulate the information easily, and later convert it to some other data structure.

Another case where this thing appears is when creating Classes in Smalltalk, where you define the instance variables inside a string.

Object subclass: #Dog 
    instanceVariableNames:  
    classVariableNames:  
    poolDictionaries:  
    category: PBE-CIV 



In The Unix programming environment, at some point they write an awk script regarding calendars, and instead of:

days["Jan"]=31; nextmon["Jan"]="Feb" 

days["Feb"]=28; nextmon["Feb"]="Mar"

...


They do:

x="Jan 31 Feb 28 Mar 31 Apr 30...."

split(x, data)

for(i=1;i 24;i+=2){

  data[i]] = data[i+1]
  nextmon[data[i]] = data[i+2]

} 

domingo, 26 de junio de 2016

Functional programming in small pieces

I've been articles on reading functional programming for some time, and little by little, I think I get a bit more of the whole stuff.

I found some nice articles/tutorials, and I understood most of them (yay!)
Although I'm still fighting with some other articles like this functional pearl about using foldr to make a function to give combinations of elements. It's been too long since I started looking at it, and I still don't get it.... :/

Well, have fun, and happy hacking.

sábado, 25 de junio de 2016

June 2016, Alan Kay is back

So it was early may 2016 when YCombinator anounced HARC, and the fact that Alan Kay and his team would be under YC's umbrella for some time (I guess 5 years at least). I got really excited. Also, some links like Alan Kay's recommended reading list. On that occasion I was happily surprised (or not so) when I saw the recommendation of Eduard deBono's Lateral Thinking.

Then, a few days ago, Alan Kay agreed to do an AMA in Hacker News, and the thing exploded.  People showing amazing respect for him, and himself answering tirelessly all questions with wise and info-stuffed answers. 'Too much' food for thought.  References to History of computers' books (The dream machine being one that I didn't know), to how to read books, state of funding, research, computers, history..... Oh, and Rich Hickey and Alan Kay discussing about data.

Today, a couple of links about restoring Alan Kay's XEROX Alto popped up in HN. And more links to Alto's hardware manual and Alto's manual.
Fun fact: One of the designers of Alto was Chuck Thacker, which was also co-inventor of the Ethernet LAN.

 And.... this post had to be published 3 days ago, but once you start looking for links on PARC related stuff, you enter the rabbit hole, and spend 3 days reading and watchin videos, without attending to any of your other duties. For me it's been these three videos. Two new one old.

Enjoy and be amused.