lunes, 18 de julio de 2011

More presentation tools

A little reminder of a couple of tools I should try for my next presentation (tbh, I don't have any presentation in near future, but..)
We'll see when someone writes org-mode + shower helpers.

sábado, 16 de julio de 2011

open rails files from console to $EDITOR

You're in the console, run rake test, and appear a bunch of file paths cluttered with line numbers, colons, and no spaces between them. Well, lest turn the no-space-between them thing in a WIN for us.

Errors and failures show in different formats when running tests (not a very *intelligent* thing if you ask me, but...). Well, a simple regex and we have 'pe' , powered-emacslient, path-edit, or whatever. In my shell, double click any of the two versions and 'pe ', and you're sitting again on your editor. placed in the correct line.

.. app/models/bar.rb:88:in ..
.. [test/unit/foo_test.rb:9]: ..



'e' is the original emacsclient script I use for other files. Unifying both scripts in one is left as exercise to the reader.

I want to spend an afternoon hacking a urxvt plugin to fetch for strings ressembling paths, and be able to open them using just keyboard, but that's a thing for another day.

jueves, 14 de julio de 2011

Sending links when you cannot send files.

I've been reviewing my ~/bin directory and felt like sharing some of the little scripts there.

Today, here's a little Perl script that helps me when having to give a file (screenshot or something) to someone @work. Most people do it by mail, or using jabber protocol. Unfortunately, emacs-jabber does not allow sending nor receiving files, and opening mail client and attaching files is waaay to slow and boring.

The way I work with this situation is having a simple http server in my computer, and moving the file there. then, I paste the link to my coworker, and he/she just has to click it and download.

The http server lives inside emacs. Oh yeah, that's irrelevant. But I had to say it.

Well, here's a script I wrote in 2 minutes.



Hashing the name is to avoid name guessing. I think I got this idea from a Mark Fowler's post that was doing something like this with dropbox.

miércoles, 6 de julio de 2011

Snapshots motherf*cker, do you speak it?


Today, I'll just snap a recipe for a use case that starts to crop up when evolving from a total git beginner to not-so-noob-git-user. git reset

Here's the diagram:



Ok, now screw it.

The main problem when thinking about how git works is thinking in the wrong way. You've been told hundreds of times that git works differently from EVERY other versioning system around, and you keep forgetting these concepts every now and then.

The diagram before is a diagram of where git moves your changes when you do a given reset command. git reset --soft foo moves the changes from commit 'foo' till HEAD to the index.

YOU'RE THINKING IT WRONG.

Remeber that you've been told that git records only snapshots? Well, think about it. When you want to reset your repo to the past, if you have a clean working directory and index. HEAD,index and wd are all in the same state. That means that All trees contain the same. THE SAME. If you are thinking that your wd has some files, that the index is empty (Delta is null) and same (or kind of) for the repo, you're thinking it WRONG again.

Now, if you go and look git help reset, and this MJD's post about git reset.

Then it's kind of easy to understand what it does, and in which state will leave your repo, index and ass.

(take the italics notes as if you just reseted the most recent commit, if you reset to older ones, all changes are accumulated)
  • git reset --soft just updates your HEAD. Changes are in the stage, ready to be commited without that nice 'fdsajflkdsajflkasdf' commit message. You're in the moment before you commited.
  • git reset --mixed updates your HEAD and your index accordingly. That means that probably, if you're reseting to past commits all changes from the target commit till now will be only in your wd. You're in the moment before you added files.
  • git reset --hard updates everything. You're in the moment after you commited the commit (O RLY?) so you lost everything you did after the commit.

Btw, Take all this post with a grain of salt. I just had an 'AHA!' moment I had to share. Probably it's not *very* technically accurate. I haven't even tried what happens on detached heads and other bizarre situations... yeah, I'm a sucker.

man git-reset contains lots of tables and info, but IMHO, naming the states of files A B C D lead to harder understanding that if they'd have been D C B A.

And now, a doubt for the lazyweb:
git reset hard does not allow you to recover your state. gitk --all does not show anything from HEAD on. but git reflog does show it. And I'd swear gitk --all worked 2 days ago....

Addendum: Here's a great article on git reset that appeared a week after my finding. Really well explained, with graphics, tables and everything.

domingo, 3 de julio de 2011

El trabajo del futuro


Via RaulGB, veo que hay empresas tan avanzadas a su tiempo, que vienen del futuro, como la rubia de la lejia, o Levi Strauss con un Delorean, o H.G.Wells.

Me guardo la oferta, espero 3 años, me pillo una time machine, que seguro que estaran inventadas por entonces, y vuelvo a por el curro.

Esperad mi llamada el martes que viene. De vuestro tiempo.

sábado, 2 de julio de 2011

Resize window in emacs

I use emacs as much as I can. That's not really news, is it?

One of my use cases for emacs is chatting with friends. I use erc for IRC, and emacs-jabber for everything else.

One thing that annoys me a bit is that when my screen is split in two and want to shrink a bit one of the two windows.

There's c-x - (shrink-window-if-larger-than-buffer) but it's only useful for a handful of situations (IMHO)

Here is a little function I wrote to shrink a window to selected region. I find it useful to narrow windows to functions, paragraphs, or just narrowing a chat window to just 5 or 10 lines.



Select a region, and run it. Then c-l to recenter accordingly.

I mainly use it as a more visual narrow-to region.

Have fun