domingo, 18 de marzo de 2018

fixing indentation of lua (busted) in emacs. A nasty hack

In general, indentation is not an issue in emacs.

But there are some exceptions.  For example, in Lua, one of the de facto testing libraries is busted, which tries to mimick rspec in many aspects.

A typical busted test looks like this:
Lua mode tends to indent code in a very lisp-y way (which I personally like) by aligning parameters to the same function using as a "starting point" the offset of the first parameter.  In this case, there's also an opened function that gets indented in addition to that base column.
This is unacceptable in most codebases, so I had to write some hack for those particular cases.

As the indentation code for lua-mode is quite complex and this is an exception to the general rule, I wrote this very ugly hack, that seems to solve my problem at hand.
As with all defadvice uses, it looks like a hack because it is a big ugly hack, but at least it lets me deal with it, and move on with my tasks without manually reindenting stuff.

Another +1 for emacs hackability :)

domingo, 25 de febrero de 2018

SF emacs meetup

This week I attended an emacs meetup in SF just by pure chance. I was browsing /r/emacs and there was a comment about the meetup. I found about it just the day before the event.

Being the first time I'm in San Francisco, and the fact that I'll be around just for a couple of weeks (for my new job), it makes it even more surprising that  I was able to go.

We were about 15 people, most from the bay area, and I think myself I was the only foreigner. The meetup topic was "a few of our favourite emacs modes", which unlocked the possibility to talk about helm-dash (not that it's my favourite mode, but is the one I wrote (and I also find it quite helpful)).

So I volunteered and gave a really quick intro to helm-dash.

Others talked about evil, magit, pynt, multiple-cursors (that was nuts!), git-timemachine, use-package, and probably some more that I already forgot.

My discoveries were:

- evil can easily create new text objects.
- learn to use multiple cursors (although I prefer vim's substitutions, mc work better for multiline "macros", and give you more visual feedback than emacs macros)
- pynt and emacs-ipython-notebook . If I ever do python again, I should remember that.
- use-package has more options that one usually thinks. RTFM
- ggtags is worth looking at if your language is not supported by etags/ctags.
- hydra red/blue modes.

Lots of fun during a couple of hours talking about tooling and worfklows with random techies.See you next time I'm around.

sábado, 27 de enero de 2018

2 ways to anchor a regex in elisp

This one I just learnt reading a PR in the melpa repo.

Usually we use ^ and $ to match the beginning and end of the line when dealing with regular expressions.

But, the same way we have \A and \z in ruby , in elisp manual: elisp regex backslash explains there is \` and \'  (that would be written \\` and \\' inside your regex string) to anchor the regex match to the beginning and end of the string or buffer. While $ matches end of the line, so "hello$" will match "hello\ngoodbye", while "hello\\'" will not.

jueves, 25 de enero de 2018

make vlc fit fullscreen window

It's an annoying thing but I was already getting used to it: VLC scales its window strangely (using ratpoison window manager), and I always have to split and 'unsplit' the frame it's in, so it adapts its proportions to the enclosing frame.

But here is the solution: 

Try this...(note: this was written using VLC 2.0.5, but it should also apply to 2.0.7)

  1. In VLC, click ToolsPreferences
  2. In the bottom left, for "Show Settings", click Simple (it might already be selected).
  3. At the top left, make sure "Interface" is selected (it should be).
  4. On the right side, for "Look & Feel", uncheck...
    • [ ] Resize interface to video size may also wanna check (or it might already be checked)...
    • [■] Integrate video in interface
  5. Click Save
  6. Manually re-size the VLC window to the size you want.
  7. Close VLC to commit the pref change & window resize.
  8. Run VLC, play some files & report if that's what you want.

It might be useful to my future self, and as I'm not sure where vlc saves its config, I might have to redo it in my future installs. (FYI, the config is saved in ~/.config/vlc/vlcrc, and the info is there, so just carry that file with your dotfiles and you should be fine).

jueves, 28 de diciembre de 2017

so this is where the msn notification sound comes from

If you remember this sound, I'll tell you  that I was listening to Youssou Ndour while hacking some Lua on my computer, and was listening to this track, And heard that familiar sound that made me alt-tab to some messaging application (which I don't have anymore).

The muscle memory reaction made me find which was the app, and yes, it's damn msn.

lunes, 4 de diciembre de 2017

New-old books for thinking about thinking

So here there are the 4 books I recently got that are keeping me *very* entertained.

Two of them are Lisp-related, and two of them are Hofstadter's.
  • The minds I : Short stories from Hofstadter, Dennet, and other sci-fi authors and thinkers. I discovered Stanislaw Lem (author of the story 'The Congress' is inspired on).  The whole book is mindblowing. 75% read so far.
  •  Fluid Concepts and Creative Analogies. Another Hofstadter's book. It goes deep in his view of what AI means, and the different phases where a human brain is creating something from nothing. Example: The sense of 50*10 being "easier" than 74*18: which are the reasons why we find that happening? Can we make machines think in that way also? Is it worth it? 40% read so far.
  • Partial Evaluation and Automatic Program Generation: I've been wanting to read that book for ages, and it's free in pdf.  The phisical copies are astronomically expensive, but I was lucky enough that my book bot found a copy for 3 euros :). It uses crazy techniques to turn interpreters into compiler generators. Futamura projections are totally mindbending. 20% read so far.

  • Building Problem Solvers: A Lisp book on problem solvers.  I discovered this techniques in Norvig's PAIP, and also CTM has some parts of Constraint Programming, and I thought that was pretty cool and broad, so I got that one also.  The book is written in "pre-common" Lisp, so no CLOS, and *lots* of mutable state, setf-ing function arguments and the like.  I'm just starting it, but I think it will be more valuable method-wise than code-wise.

viernes, 10 de noviembre de 2017

asm and reverse engineering

I've been lately giving a shot to some assembler tutorials. Just because.

I never did any serious assembler, but when I was into reversing I was eating asm for breakfast, but from the read perspective.

In there are the few codes I wrote, either following tutorials, or walking random paths myself, using nasmx macros.

In windows, there's MASM and NASM, but MASM is not in GNU/Linux, so the option was NASM. It's nice that it gives me the same syntax I was used to in the old days using W32Dasm, ollydbg, soft-ice and friends.

Anyway, I've been looking at nasmX, which are a bunch of macros that lift assembler a bit. At least, allowing you to write with ifs, whiles, and "forgetting" about the calling conventions. Super cool!

Meanwhile, I've been also following some reverse engineering forums, and rediscovered RE a bit. A nice fuzzy feeling that many things are the same, but tooling changed (radare2 is a must in linux, and the learning curve is vim-like).  Still, I'm starting to do my first hacks on android using anbox, apktool, and jd.  very basic stuff, but nopping a few things and rerunning them in the mobile is already an achievement!

 As always, lots of resources, and not so much time to swallow them.