sábado, 29 de diciembre de 2012

using ido-completing-read to get input from users

Lately, ido is my shortcut to many commands that I used to execute in shell. It's great to have a flexible matching with autocompletion, inside your development environment. The function to call from your elisp code is ido-completing-read which has the following signature:

(ido-completing-read PROMPT CHOICES &optional PREDICATE REQUIRE-MATCH

Let's see an example of using ido to collect a parameter from the user. I have my favourite streaming radios stored in pls or asx files, and this little function allows me to type M-x radio RET to listen any of those.

 (defun radio ()
   (let ((filename
         (ido-completing-read "which radio?: "
      (concat "mplayer -playlist /home/rgrau/bin/radios/" filename) "*mplayer*" )
     (message "choosen: %s" filename)))

Now you can easily port many commands you used to run on terminal to be executed inside your favourite editor.

EDIT: A copypasta fail made this post appear like without body in planet emacsen. sorry :(

jueves, 29 de noviembre de 2012

a neat ruby idiom

[rgrau] guys, I just learned a new idiom  
[rgrau] (@foo ||= []) << bar  
[michal] :)  
[rgrau] It's not crystal clear, but I like it  
[rgrau] my perl background damaged my brain beyond repair
[jakub] rgrau: idiom or idiot?
[rgrau] you pick
[jakub] ok, done
[rgrau] I know which one you picked  
[jakub] u r smart
[rgrau] u idiom
[rgrau] that log goes to my blog inside ruby section

sábado, 24 de noviembre de 2012

'symbols, :symbols and ':symbols

The other day, hacking a kind of project manager for emacs (YES. Another one) which I will explain in a future post, I bumped in a couple of wtfs, that turned out to be my own mental fuckup, not an elisp wtf.

Let's dissect plist-get with different kinds of atoms as keys, and try to explain why they work or they don't. Little schemer style.

(plist-get '('directory ":fdsa" 'irc "channel") 'directory) ; nil

Why? The whole plist is is quoted, being a literal list, so if there's no need to re-quote it again.

(plist-get (list 'directory ":fdsa" 'irc "channel") 'directory) ; ":fdsa"

Why? We built the list with the list constructor, so we have to quote the symbol directory. because we want a simbol.

(plist-get '(:directory ":fdsa" 'irc "channel") 'directory) ; nil

Why? :directory is a different symbol from 'directory, and the whole thing is quoted.

(plist-get (list :directory ":fdsa" 'irc "channel") 'directory) ; nil

Why? the plist is not a literal, but again. :directory and 'directory are different things

(plist-get (list :directory ":fdsa" 'irc "channel") :directory) ; ":fdsa"

You see?

(plist-get '(:directory ":fdsa" 'irc "channel") :directory) ; ":fdsa"

And this is again correct. Makes sense, no?

Then, the relation between :foo and 'foo is none, but (eq :foo ':foo) is t.

jueves, 22 de noviembre de 2012

emacs taking to much memory?

[p1] my emacs takes up more memory than firefox, hm
[rgrau] open more firefox tabs
[p3] install more extensions

I love #emacs help style :)

domingo, 18 de noviembre de 2012

If you are planning to change jobs in the programmers' world, make sure you read some of these articles. They all have very good points about what the authors think you should consider when looking for your _next_ job.

If you're not looking for a job, I'd recommend skim through them also.

They make a lot of good points IMHO, but I'll let you read them by yourself.

jueves, 25 de octubre de 2012

HTTP status codes explained in IRC

*p1 is sending GET request since 2001
[p1] and still no response
[p2] 422
[p3] malformed bitch
[p3] ah no, unprocessable
[p1] i don't do that sick stuff
[p3] unprocessable bitch
[p1] girls quite often reply with 403
[p1] if it doesn't help, they go 404
[p1] some even try 300 to their friend which is very pathetic
[p3] trying to DDOS

martes, 16 de octubre de 2012

VPNs explained in IRC

[p1] meth. I've told you
[p2] lovely
[p2] it's like a VPN
[p2] you're comunicating where others just see noise
[p3] lol
[p3] that's a great quote
[p2] the guys from the other side of the vpn told it to me

domingo, 14 de octubre de 2012

github -> emacs : org-protocol-github-lines

Hello emacsers,

Today I'd like to present a hack I've assembled after being tired of going from github page to emacs looking for a given file/line repeteadly.

Say you collaborate in a project that's hosted in github, and you issue a pull request. If the team is minimally careful, someone will look at your code, and comment on it, pointing conventions you didn't follow, or pointing to buggy code you didn't notice you were introducing. At work, we are continuously doing comments in others pull requests as its part of our workflow.

So, wouldn't it be nice to have a custom button that opens your favourite editor in the correct file and line you're just staring at, but in your browser? Ok, that's what this hack is for.  The puzzle has 3 parts:


 When you check the pull request someone commented, you normally see something like the following.

Then you normally look at the file name, the line and the comment, and try to remember the three pieces of info, go to your editor, fetch the file, line and do the appropiate modifications.

Well, with org-protocol-github-lines  (yeah, the name sucks), you'll be presented with this: 
And the new link will point to "org-protocol://github-comment://kidd/org-protocol-github-lines/org-protocol-github-lines.el/28" .  This is done via a simple chromium userscript. (Alert, I suck at js, it's a complete hack)

Operative System

The second part of the puzzle is teaching your OS that org-protocol:// URIs should be opened with emacsclient. After trying some methods I found on internet and being unable to make any of those working, I went for the naive approach of copying xdg-open to my ~/bin directory, and patch it accordingly to open org-protocol:// URIs with emacsclient.  The complete xdg-open is in the git repo.


And the last thing is the elisp part. when emacs receives an uri starting with org-protocol, you can use some org-protocol helpers to decode the parameters and such. The relevant info is in the org-mode page.

There's an alist called org-protocol-projects that you should modify to map "user/repo" -> "path/to/the/root/of/the/repo/(local)" .

And here's a video that shows the whole thing in action.

Demo of org-protocol-github-lines emacs plugin from Raimon Grau on Vimeo.

If you find more places where it makes sense to add those links, or have anything to coment, please use the comments here, or github issues, or find me in #emacs and #emacs-es as rgrau or rgc.

Clone it from https://github.com/kidd/org-protocol-github-lines

lunes, 8 de octubre de 2012

sábado, 22 de septiembre de 2012

the gif is dead, long live the gif

Just a couple of funny links I read last week on gifs, and embeded animations on the web.

Here's a library that uses animated gifs as a way to comunicate with browsers. gifsockets is written as a joke o proof of concept, but anyway the idea is cool.

In the last days, after the presentation of the iPhone 5, there was also some discussions around on how and why they managed to put an animation on that website that would be playable in all devices, and would be high quality and wouldn't weight too much. It's funny how we have to fight the same old problems daily, and there's no fixed solution.

<rant> New platforms are so flaky that they don't even try to comply the standards, and they evolve from naive patch to naive patch to solve immediate problems, making them more and more appart one from the other. Everything is fucking broken, and you have to be an expert even to put a short animation online. And Apple is not the only one doing these tricks.  That same hack has been used for many others. SublimeText, for example also used this trick. Very clever, but fuck, that's not blackbox abstraction, when You have to think about how your animation will be encoded when doing a web.</rant>

Well, and the appropiate HN pages, just in case you wanna dive into the comments.

martes, 18 de septiembre de 2012

emacs checking your temperature

Yesterday I was on my laptop, with the usual tools opened (that means emacs, urxvt+screen and chromium-browser).Nothing strange. I went out for a rollerskating session with a couple of friends and when I came back, the laptop was awfully warm. I mean, keyboard really hot, and when I took the laptop on my hands, it was freaking hot. Luckily it didn't melt :).  A quick glance at top(1) showed that chromium was taking all the cpu, and a big amount of memory. probably some js, who knows.

Just killing the offensive process made my little old thinkpad come back to normal temperature.

Then, to make sure it doesn't happen again, I wrote a little elisp script to warn me in case my lappy is warming beyond acceptable limits. Or even kill chromium-browser in case the temperature is >95C.

So here's the  code. Checking the temperature of the cpu, and acting if needed.

;;; raimonster@gmail.com
; The array returned by battery-statys-function => '((99 . "25330") (76 . "on-line") (100 . "54") (114 . "0 mW") (66 . "charged") (98 . "") (104 . "0") (109 . "0") (116 . "0:00") (112 . "97"))

(defun rgc-check-for-hotness ()
  (let ((temp (string-to-number
                (cdr (assq (string-to-char "d")
                           (and battery-status-function (funcall battery-status-function)))))))

    (cond ((> temp 95) (async-shell-command "killall -9 chromium-browser"))
          ((> temp 75) (message "FUCK! I'M HOT"))
          (t (message "ok, no problemo")))))

(defvar rgc-hot-timer nil "timer")

(defun rgc-hot-hot-hot ()
  (setq rgc-hot-timer
        (run-at-time nil (* 60 5) 'rgc-check-for-hotness)))

(defun rgc-stop-hot-checker ()
  (cancel-timer rgc-hot-timer))
As always in this blog, no rocket science, but (hopefully) useful bits of elisp.

sábado, 4 de agosto de 2012

Back to Vec

  If you've followed this blog, or you know me, you know I've been a
   vectorlinux user and collaborator for a few years.  Lately, I didn't
   use it and favoured Ubuntu and Arch. The change was done because I
   needed packages that weren't in the official vl repos, and were not
   trivial to build. And was lazy.

   After 1 year (more or less) I found another opportunity for vl, and
   I have to say I'm happy to have tried it.

Installing vectorlinux

   I'm using a Lenovo thinkpad X61, and it doesn't have CD, so the way
   to get a linux running there is booting through an usb drive.
   I used unetbootin + VL light 7.0, and found the first
   issue. There's some missmatch between unetbootin versions and vl
   image format, and my unetbootin left the boot image in
   isolinux/kernel/sata instead of /syslinux/kernel/sata . Just
   copying the directory to the other place solved the booting issue.


   As usual, everything worked as expected, no glitches, and all
   configs did their job.


   After installing a linux distro, first thing to do is installing
   the 'must have' apps.
   - edit /etc/slapt-get/slapt-getrc and enable a few more repos
   - slapt-get --update
   - slapt-get -i ratpoison

   Nice we have 1.4.5 there :). Then, let's go for emacs. OOps,
   there's just emacs 23.X in the repo.

   As a side note, I have to say that besides not having used vl for a
   year, I kept an eye on the irc channel, and I've kept in touch (and
   sometimes giving a hand or opinion in vl projects) with rbistolfi 
   (one of the devs).

   Long story short. After pinging rbistolfi and asking for emacs
   24.1, I had a working package in 30 minutes. And the effort is not
   lost, but all the work is prepared to be pushed to the repos.
   While doing my usual instalations, I found some missing packages in
   the repo, so asked for a way to contribute back. You know, I wrote
   the package that vl still uses to build packages, but now I see the
   workflow is much more streamlined. See it in the NEXT POST (NIY).

Early opinion

The first impression is that the whole system is faster than ubuntu. As always, the package selection is really nice, and not having to install 5 related  -dev packages but just one when I need a feature is really confortable.

I already comited a couple of packages to the repo, and found some bug in sbbuilder that I'll try to tackle this weekend.

Vectorlinux, I'm back!

martes, 24 de julio de 2012

Maybe google doesn't know so much about me

Ok, I just used G+ for a few days, and I find some interesting people in there, and also read all that hype that's having, so I decided to explore it a bit, and maybe add people I know IRL to G+ (I  refuse 70% of known people, also on facebook).

I found a tab named "Explore", and thought that maybe these guys would present me something useful. A g+ walkthrough, or interesting posts (hint: TED talks or Google.IO). So here are the first 3.

Jooooder, suputamadre, and many more spanish swearing words after seeing the 'highlighted' posts that google selected for me. It's like quantum leap happening and being an average retarded 15 year old.

Google, I like programming, music, skating, partying, science, art, books, and pr0n.

Thank you.

sábado, 21 de julio de 2012

When mapcan backfires

While writing some elisp for clasker (still alpha), The destructive function mapcan backfired in a really strange way.

Calling mapcan on a list of really simple functions that just returned lists, worked ok, but just the first time.

The issue is a combination of different things, mainly Iterating through functions that return quoted lists.  When nconc does its thing, it uses the lists in place, so we're indeed modifying the defuns.

Here's the small code that exemplifies the issue, and a possible way to avoid it.

ELISP> (defun t1 () '("hola"))
ELISP> (defun t2 () (list "adeu"))
ELISP> (t1) 

ELISP> (t2)

ELISP> (mapcan 'funcall '(t1 t2))
("hola" "adeu")

ELISP> (t1)
("hola" "adeu") ; => Oops, t1 has been modified

ELISP> (mapcan 'funcall '(t2 t1))
("adeu" "hola" "adeu")

ELISP> (t2)

ELISP> (defun t1 () '("hola")) ; Redefine t1 and t2 for sanity assurance
ELISP> (defun t2 () (list "adeu"))
ELISP> (mapcan 'funcall '(t2 t1))
("adeu" "hola")

ELISP> (t2) 
("adeu") ; => t2 is fine

Generating the lists with the (list ...) function solves the issue, because a new object is created every time, so we're not returning the literal object from the source.

Also,  (reduce 'append (mapcar ...)) will do "the right thing" (tm)

jueves, 5 de julio de 2012

Learn javascript as a little schemer

I recently found a blogpost talking about javascript prototypes in a very funny and uncommon way. It was funny to read, easy to follow, and high on insights. Out of the sudden, something clicked in my brain, and I thought:

 - Aha!, I've seen this way of explaining things in some other place! It's like the Little Schemer (and all the schemers collection (which I haven't read (yet)))!

 Then, I checked other posts on the same blog, and most articles follow the same socratic experience of explaining things.

 Really, it's funny, and it builds up on you.

 Well, and here's the url of the blog. Kudos to AngusCroll (author), you have a new blog follower.

EDIT: I just found another instersting post for js wannabies like me. Simpler, but interesting read

miércoles, 4 de julio de 2012

"Chrome does UDP sockets" joke

Opening a new section, here's the first post in the new section irclog, where I'll just copypaste remarkable pearls that appear in one or other channel I'm usually logged. Be prepared for geek jokes. I can't promise to be involved in all :) And here's the first. with my 3scale coworkers
<a> http://blog.alexmaccaw.com/chrome-tcp-udp "Chrome supports TCP & UDP Sockets"
<a> you can do udp jokes in chrome now
<rgrau> I didn't get it
<a> I don't care
<rgrau> great!

martes, 19 de junio de 2012


Hi again emacsians.
Maybe you're familiar with this IRC log samples.

  15:54 [rgc] xb
  15:54 [rgc] ooops, C-fail

  12:02 [xyz] ls
  12:02 [xyz] oops

  00:21 [foo] cd
  00:22 [foo] wrong buffer :/

To avoid that, some time ago I wrote some elisp to make erc-buffers read-only, but I just came up with a better solution:
(defun rgrau-erc-oops (txt)
  (when (member txt '("ls" "xb" "cd"))
      (setq erc-send-this nil)))

(add-to-list 'erc-send-pre-hook 'rgrau-erc-oops)

It's too simple to make an erc module out of that(isn't it?), so I just put it in this blog entry.

jueves, 7 de junio de 2012

erc-button fun

Erc is one of multiple irc clients bundled with emacs.  It's probably the most complex one, in fact, in #emacs you read that quite a few people left it in favour of simpler clients like rcirc. But I kind of like its complexity :)

One nice thing about erc that's not very known is erc-button.  Yeah, the thing that allows you to click on nicknames and kick them :).

At work, we use github issues to manage our stuff, and we wrote a super simple extension for our bot that whenever it sees #number it just pastes the url of the issue. I tried to use a more silent approach using erc-button, and here's the result.

It just highlights #123 like strings and make them clickable, linking to the appropiate issue in the appropiate repo.

Neat, no?

Well, if you happen to use other sites for your issues, you can work around that github-centric approach with something else, I just hacked an ugly solution on top of the previous one. Not very clean maybe, but working.

Probably, the most sensitive solution would be writing the whole urls for each one, but well... :D

The nice point here is the tight relation between emacs and all other tools and use case. In really few lines of code we solved a problem, and we did it flexibly enough to be used in multiple scenarios.

Btw, hi to all planet emacsers, that's my first post here since I signed in. I hope to contribute here some of my emacs tricks. Don't hesitate giving feedback and commenting.

Update: There are gists inlined in the post that aren't visible in planet emacsen.  Will try to change approach for the next one.

martes, 15 de mayo de 2012

Lisp debugging, step by step. Step 1

Debugging lisp is not as straightforward as one might think at first.  Being a live environment I thought it would be a joy, like in smalltalk, racket, or elisp, which provides a quite decent tracer and stepper.  Smalltalk is another world, but I'm already getting used to it so it doesn't surprise me that much.

We all heard stories about lisp machines (genera), and eventually read some article or seen some talk about how awesome it's lisp to debug.. but for me it was not so straightforward.

I'm using SBCL for all my experimentation in CL, so the examples here are going to be all sbcl related.  First of all, some reasons on why there's not an easy mapping between your debugger on the language next door and lisp when debugging:

- Lisp normally compiles the source code to native code. Doing so, it runs lots of optimizations on your source, so the code executed has no direct mapping to your written code.
- Lisp is not line oriented, so the order of execution of code is not so easily mappable to the typical next-line, next-line... debugging.
- On the other side, you have 'trace' that lets you track all executions of a function, with params, and so. It's not so live, but with all the instrumentation that sbcl and slime provide, you can track down a fair amount of bugs just with trace.

To instrument a method to be debuggable more easily, my advice is to add this declarations.

  (declare (optimize (speed 0) (space 1) (compilation-speed 0) (debug

That'll keep sbcl out from doing optimizations that can make variables 'disappear' in runtime.

A little more info in:


and obviously, in your nearest implementation manual http://www.sbcl.org/manual/Debugger.html

lunes, 14 de mayo de 2012

CompGuile. Compile guile in ubuntu

Guile is the Gnu Scheme implementation and official extension language for gnu apps. Let alone most gnu apps disregard this rule. I always found guile a good companion because it was easily instalable in all my linux boxes.

 The other day I tried to install a newer version to work with geiser (and because I had been reading some nice things related to new versions on Wingo's blog), but the installing process wasn't as simple as ./configure && make install. Mostly my fault, because I just needed many *-dev packages that were not present in my box. But after installing gmp and some other easy-to-find libs, I got stuck into "No package 'bdw-gc' found". As jao put in a mail in guile maillist,

"You can tell configure where BDW is located by setting the above
mentioned environment variables. With libgc-dev installed from a deb, i
routinely do (in a bash prompt):

  $ BDW_GC_CFLAGS=-L/usr/lib BDW_GC_LIBS=-lgc ./configure

domingo, 13 de mayo de 2012

imap for emacs (insert templates on emacs)

You just miss good old :imap for your temporary configuration of your editor (remember vim?).  When you know you'll be going to insert similar strings over and over.

And you love the way vim allowed you to do crazy stuff inside a map.  But now you're in emacs, so let's see how we can scratch your itch.

My concrete case was inserting strings like (?* ?x) where x is a parameter.

  •  Skeletons. Skeletons can do that and much more. it's a classical template inserter.  For example, you can setup a skeleton of the desired output and interleave str symbol, that will be replaced for the input you'enter.
    Skeleton can do more sophisticated things, like inserting multiple lines while user keeps entering data.  I can imagine myself using this when entering lots of data with some desired format.

  • Yasnippets. Yasnippets are skeletons on steroids. Sad thing is that there's no direct way to bypass the file used to define snippets. I guess you can open a new buffer, put it into yasnippet-mode, and c-c c-c to activate the binding for just this session, but maybe it's too much of a hassle.

  • defun+insert.  The dumb way to do it, but the most straightforward if you tend to forget rarely used functionalities like skeletons.  Just define an interactive function that inserts your shit there, and call it at will.  That's the option I go when I don't wanna spend a minute looking for skeleton docs.
Then to call the functions/skeletons, you have different ways, if you want to global-set-key, or even just set the key in insert mode (using evil), reminding of imap style,

I'd love to hear other solutions on that same issue. Any suggestions?

sábado, 12 de mayo de 2012

The art of demo programming

Some time ago I met a guy on the internetz that was quite fond of demoscene. I never looked at it before, but since then,, I'm quite amazed by everything related to demos.

BIG BIG respect.

 From programming techniques, to creativity. Raymatching, compressing, and music. Everything pushed to its limits. There's been a recent thread in HN, with a quite a few links to tutorials, videos. 

And here's the freaking amazing demo that started the hn thread. Prepared to shit bricks? All that thing fits in 4096 bytes.

Yeah. 4kb.


jueves, 3 de mayo de 2012

simple made easy, twice

Here there are a couple of videos of the same talk "Simple, made easy", by Rich Hickey. I love Rich's talks, and I think it's even enlightening seeing the same talk twice, fine tuned for different audiences.

First one is from RailsConf 2012 Keynote. Done with a ruby audience in mind.

Second one is from StrangeLoop 2011. much more hilarious and punchy IMHO, and maybe a little less serious tone, but equally enlightening.

Here it is. bye!

lunes, 23 de abril de 2012

elisp of the day: undefine a defun

Elisp is a pretty archaic lisp. I'm not refering to the problems everyone talk about (dynamic scope, One namespace to rule them all,...) but the aspect of being very rudimentary in its construction.

That's why there have been several attempts to substitute elisp for something else (let's rewrite emacs in erlang!). For me, it's doing pretty well, and now that we have lexical scope there, I think I can live with prefixed-and-very-long-method-names.

A positive thing of elisp being archaic is that the system is wide open to users, and most things are just obvious (once you were given the proper explanation, heh).

One place that doesn't work like that is when redefining a defun to defmethod. setfing the symbol-function to nil does not work. (It makes the old defun inaccessible, but doesn't free the symbol)

That's why fmakunbound exists. fmakunbound 'symbol,  and after that you'll be able to defmethod on that symbol.

For now, I haven't found any other real use case for that, but I can imagine unloading a package by removing all methods it previously defined.  That's not much in the culture of emacs though (never seen any plugin that does that) 

sábado, 31 de marzo de 2012


Video molt interessant per passar-lo als vostres pares (o fills), per explicar-los de que va la historia 'del internes'. Privacitat, entorn, poder, efecte bombolla. La qualitat divulgativa es bonissima. Jutgeu vosaltres la dels continguts.

sábado, 17 de marzo de 2012

shell and vim superpowers

It seems that the commandline is making a comeback, maybe with some hype. At least, I keep seeing more and more articles with titles like 'vim advanced features', courses like 'programando a toda leche con vim' (that are not cheap at all), or extensive articles like use unix as an ide or the zen of the vi wu wei (I like these 2), and other articles with this similar topic. It's amazing how people are reinventing the same wheel every other decade.

But out of these new tutorials that (mostly) bring nothing new to the scene, once in a while you find some useful tips or tools that people build that add orthogonal functionality (if that concept exists), and allow faster access to things, or better interface to them (note the orthogonality of the word 'thing').

You know, there's no problem that another level of indirection can't solve. So here you are. a couple of projects that allow you to refer to files, directories, and git stuff by numbers. fasd and git-number . The first one based on autojump.

Unfortunately, the web is so volatile that I can't find many of the top 10 vim articles from past decade, but I have seen isomorphic articles to this one by thousands. during the last 10 years.

So welcome guys, let's invent the future now! :)

domingo, 4 de marzo de 2012

more macros

Some links to useful/cool/smart lisp macros are appearing in that reddit post . There are a few really nice examples: from 'simple' templating systems to output html from Lisp, to more or less sophisticated macros-that-generate-macros, and even execute comments using reader macros. And the amazing factor-like stack concatenative language inside emacs (||| lisp-val: (list 1 2 3 4) { 1 + } map { 2 > } filter )

Here is a page where you can find most 'standard' macros from On lisp, ready to use for emacs lisp. I've used some of them for my new emacs project I'm doing with davazp.

There are also some nice macros in the third part of lisp for the web articles.

And here's a nice example of how awesome can 25 lines of lisp be. Not sure it's the best macro example, but got a smile in my face the first time I saw it.

miércoles, 29 de febrero de 2012

functional javascript

I already wrote one post some time ago about some javascript that enabled more confortable functional style programming.

Now I come with a few more (that mostly bring bundled functional capabilities in a single package)

Here's a library that brings map,filter,reduce,currying, and some inline string->function->evaluate automatisms.

And a more DIY text with quite a few nice tricks.

jueves, 9 de febrero de 2012

Kiss the cuke

I don't care if you're cuking it right or wrong.

But you can use cukes whatever language you use.
So, there's no excuse, if you like BDD, not to use it.

w3m-redirect automatically

You could take this post as a second iteration on this older post.

There are many urls that are fairly navigable on w3m (emacs-w3m that is). The less html-y the site is, the more confortable it is.

So here's a way to redirect gist links to the raw plaintext counterparts. I just wrote it in 5 minutes, and it's quite inestable, but for the moment, it Works On My Machine. I'll try to make it more general and robust in next few days (as always, with advice from davazp)

Btw, it doesn't work if there is more than 1 file in the gist.

lunes, 6 de febrero de 2012

new emacs mode: expand-region

There's a new mode for emacs that has recently came out. It's called expand-region, and it's probably the nearest we can get to text-objects in emacs. In fact, it's quite interesting that it can be extended for specific major modes.

I had much of the same idea 1 month ago, and tried to implement the same functionality, but failed miserably (kind of worked, but really ad-hoc and hackish).

The basic idea of the plugin is selecting incrementally different semantic units with the same shortcuts.

Mangars is the author, and has kindly applied a couple of pull requests I made (hey, it's my first collaboration in any emacs plugin). I basically added support for disabled transient-mark-mode, and extensions for feature-mode.

On the way, I found out that ecukes and espuds. Nice discover.

And here's my fork of expand-region (that hopefully, you won't need to clone, because the central one is magnars')

Musicz from 10 to 7

What music do you listen to while programming, or just working in front of the PC?

For me that's from Guns and Roses, the Doors, soul and acid jazz, to Fat Boy Slim, Propellerheads, Prodigy and psy-trance.

Here are some comments on HN related to what programmers listen to when doing their job.

* http://news.ycombinator.com/item?id=3547694

* http://djbolivia.blogspot.com/2011/04/music-to-code-by-volumes-1-3.html

And you? what do you listen to while programming?

PS: I got 0 comments on that, and knowing that just a few people reads my humble blog, and many of you are people I know, and I know you listen to music while programming, and on the other side, a good deal of programmers like to listen music while working, I'd love to have responses. otherwise, I get very little motivation to keep up with this blog. C'mon lazyweb. Let's see how it goes with G+.

sábado, 28 de enero de 2012

Lisp and the web (probably part 1)

I've tried some lisp frameworks with different intensities and approaches, without settling with anyone of those. Just looking around.

As a first approach, I'm going for the minimalist frameworks. Caveman (on top of Clack), and RESTAS.

My first experience is with caveman, as I want something really simple, and known. Not that I've worked with Sinatra/Rack nor Flask/WSGI, but at least, the architecture is more well known that with other fw like weblocks or RESTAS.

With Toni, we've been hacking a bit our way to do a super simple micro app. And we stumbled upon a few WTFs, or undocumented Caveman spots, or just blockers for us due to our lisp newbieness. Luckily, most of them are solved now :)
  • In GETs, (getf params :id) work, but in post POSTs, the symbols are presented in a different format (getf params :|id|). As davazp pointed, this probably has some problems issues with CL never garbage collecting those interned symbols.
  • clsql:*default-database*. clsql will use *default-database* database handler if you dont's specify any. This makes using clack's middleware for clsql transparent from caveman apps.
  • Getting caveman through quicklisp threw some erros during installation. Installing newer version of sbcl just solved it. (http://comments.gmane.org/gmane.lisp.steel-bank.announce/111)
     * new feature: SB-EXT:VALID-TYPE-SPECIFIER-P returns whether a given type
specifier is valid where "valid" basically means "would be accepted as
second argument of TYPEP".

  • cl-project doesn't create the link in ~/quickload/local-projects on new generated projects . If you create your projects under ~/quickload/local-projects, quicklisp will be able to quickload it, but if you put it somewhere else, you should create a link to your project.

I'm now struggling with form-builder, and widgets (no docs nor examples at all). We'll see how it goes.

before forgetting them

A couple of amazing links for the weekend

miércoles, 25 de enero de 2012

stylish ruby

Here you have a couple of style guides related to ruby, rails, and some tips on functional programming and a few not-so-trivial techniques like currying, TCO, or just using immutable structures.

Apparently, all things explained in all those guides are obvious, or just a matter of taste, but you better read those guides a few times each to make those rules stick in your head, just to be sure :)

First, a guide from bbastov (of emacs prelude fame), that's already in github and forked more than a hundred times, so we could say it's a community ruby style guide.

Second, another bbastov's guide, this time on Rails 3.

And last but not least, slides of a friend of a friend's workshop on Functional Ruby. Really nice, and full of nice tricks that deserve to be read and understood.

That's all for now. Back to hacking

viernes, 20 de enero de 2012


Step by step, I keep getting more and more of what's lisp about.

Not just the syntax (huh?) or the core lib, but idioms, design decisions, and the vision.

One of the mottos of Lisp is the famous 'code is data, and data is code'.
For me, that's not 100% clear yet, but I get more insights every day.

One implication of this is when you look at s-exps and see them as a datastructure, not as code. That's the macro point of view. If you want to know more about macros, I can only recommend you Paul Graham's OnLisp, and Doug Hoyte's Let Over Lambda. I'm now reading through the latter and I find it a perfect companion for OnLisp.

The other direction is 'data is code'. To exemplify this side, here are a couple of links that really get to the point of this (at least one part of the point).