syntax highlight

Friday 27 March 2009

Vim tips: Using macros

Clik-click tap, clik-click tap, clik-click tap. A team mate is performing some kind of repetitive operation with text and it's becoming more and more annoying. Good news, there's a way to keep your mental sanity and help this guy to be more productive: replace him with a sed/awk script teach him how to use Vim macros!

Vim macros can repeat for you a sequence of commands. Press qq to start recording, then q again to stop. Use @q to execute a macro. Let's try it:

This - random garbage
is - random garbage
a - random garbage
sample - random garbage
text - random garbage

So, how would you get rid of the random garbage? Move the cursor to the beggining of the first line, press qq to start recording then f- to move the cursor to the dash and d$ to delete the rest of the line. Now move the cursor to the begging of the next line (0j) and press q to stop recording. Now press 4@q to repeat the macro for times and check the results; you should have something like this:

This
is
a
sample
text

Neat, huh? You can also store any number of macros using a different letter after the q to start recording, for example qn to record and @n to execute. Also, use @@ to execute once again the last executed macro (from any buffer).

There are some more things you can do with macros (like editing before executing one) but the best source for that is the manual.

Monday 23 March 2009

Valgrind - OCI: Suppressions file FTW!

Update: There's a new Valgrind suppressions file @ this link.

Working [1] on a C++ project with Oracle I found that Valgrind reported lots of warnings related to OCI, for which, regardless of being false positives [2] or not, there's little I can do about (other than migrating to MySQL, that is). As the error report kept growing I found that Valgrind will refuse to keep track of new errors after a million or so:

More than 1000000 errors detected. I'm not reporting any more. Final error counts may be inaccurate. Go fix your program!

The solution in this case is a suppresions file for Valgrind. After spending a good deal of time unsuccsesfuly trying to get one I had to do it myself and upload it for the next one to run into this problem:

Link to the file: Valgrind / OCI suppressions.

Saturday 14 March 2009

Vim tips: Moving the cursor to a letter

Let's face it, Vim is the best editor in the world, and from now on there'll be a spot in the homepage with a "Vim Tip of the Week" (check the sidebar).

For the first one a basic tip: Moving to a letter

While in command mode press ' f' and any other letter; the cursor will move to the first occurence of this letter. This can be combined with other commands and a number of repetitions (e.g. ' d2f.', to delete until the second dot).

As a sidenote, I guess there must be a Word Press plugin to display the latest post in a category but I coudn't find it, so I hacked my own: tip-of-the-week

Tip of the Week

I recently added a new plugin to display the latest post within a category; there must be another one out there but I coudn't find it, so I hacked my own. I plan to upload it to WP's plugin repository (some day) so I may as well use this post a man page (?)

  1. Download the plugin from // TODO

  2. Unzip / untar the file in wp-content/plugins

  3. Enable the new plugin

  4. Configure the category to be searched (in my case I used "Vim Tips") in the settings tab

  5. Add the plugin as a widget (or copy&paste the code as needed, it's in the readme)

  6. Post something within the new category, if there's nothing

  7. The excerpt from the post and its title will be displayed in the sidebar (or wherever you configured the new plugin)


Easy to use. Hope you like it.

Friday 6 March 2009

Introducción a GNU Linux

Subo una presentación que usamos para dar una charla de introducción a GNU/Linux en la UTN a principios del 2008 con el grupo GNUTN, orientada al desarrollo. La charla salió muy bien pero todavía no hubo quorum para armar una nueva.

Link a la presentación (PDF)

 

  

También dejo link en la sección de artículos.

Monday 2 March 2009

Valgrind FTW

Una presentación que armé para el trabajo con una introducción a Valgrind, herramienta para profiling y debugging, principalmente para C/C++ en Linux (es posible usarlo con otros lenguajes pero nunca probé): Link al artículo (PDF)

También dejo el link en la sección de artículos.