Common Computing

June 21, 2008

Vim - search all files in argument list

Filed under: Uncategorized — th @ 12:53 pm

update june 24th

you can search in all files in the argument list with this command:

:vimgrep {searchpattern} ##

thanks to mihi who pointed me at the special cmdline wildcard ## that expands to all argument files. this obviously does not work with version 7.0 because in this version vim encloses the file list with double quotes.

plugin for vim version < 7.1

install: save as ~/.vim/plugin/arggrep.vim

usage:
:Arggrep {searchpattern}

see vimgrep for more info.


" Vim global plugin for searching all files in :args
" Last Change:  2008 June 21
" Maintainer:   Thomas Hammerl <thomas.hammerl %_at_% gmail +_dot_+ com>
" License:      This file is placed in the public domain.

if exists("loaded_arggrep")
  finish
endif
let loaded_arggrep = 1 

function s:arggrep(searchexpr, bang)
  let files = ""
  for arg in range(argc())
    let files = files . argv(arg) . " "
  endfor

  execute "vimgrep" . a:bang . " " . a:searchexpr . " " . files
endfunction

command -nargs=1 -bang Arggrep :call s:arggrep(<f-args>, "<bang>")

March 3, 2008

Vimperator

Filed under: Uncategorized — th @ 3:12 pm

The Vimperator is a really cool Firefox extension which makes it look and behave like the Vim text editor.

For me, the most helpful commands turned out to be:

Command Description
k, j scroll up and down
<C-u> and <C-d> scroll up and down half a page
o <url> open url
t <url> open url in new tab
y copy the current location to the clipboard
H go one step back in the history
L go one step forward in the history
/, ? search forwards, search backwards
gh go to start page
gg go to top of the page
G go to bottom of the page
m[a-zA-Z], ‘[a-zA-Z] m marks the page and its position. ‘ visits a mark. [a-z] are local to the tab. [A-Z] are global.
:b Gm<Tab> in this case: go to tab with title starting with “Gm”. in my case, that’s usually my Gmail inbox.
d closes current tab
r reload page
:pa[geinfo] displays information about the page (i.e. mime-type, encoding)
:prefs opens preferences window
:addons opens addons window
:help opens about:blank (Vimperator help)
ZZ close Firefox

Additionally I’ve defined the following things in my ~/.vimperatorrc:

set guioptions+=b
map f ?\L
map s ogoogle.com

The first line adds the bookmarks-panel to the Firefox GUI (the toolbar, the menubar and the bookmarks-panel are all hidden by Vimperator by default).

The second line maps the f-key to a backwards search in links. This way I can quickly navigate through pages with the keyboard by pressing f<some link text>. This can also be achieved with Firefox alone by pressing ‘<some link text>.

The third line maps the s-key to google.com.

In combination with the It’s All Text extension I’m really feeling at home now.

February 25, 2008

Ein RSS Feed für das Zeit im Bild Weblog

Filed under: Uncategorized — th @ 5:05 pm

Das Zeit im Bild Weblog ist ja inhaltlich hervorragend, technisch jedoch leider etwas bescheiden. So gibt es bis gestern kein RSS Feed, um das Weblog mit dem Feedreader seines Vertrauens zu verfolgen. Ab heute gibt es aber eins, denn ich habe mit Yahoo Pipes eines gebastelt. Allerdings enthält es nur die Titel und die Links zu den Einträgen. Den Inhalt zu parsen war mir bei der chaotischen HTML-Struktur zu mühsam.

ZIB RSS
Infoseite zur Pipe

Und so sieht der “Source Code” der Pipe aus:

Update 25. Februar 23:58 Uhr:

Ausgezeichnetes Timing:

“Demnächst soll es auch einen RSS-Feed geben.”
http://zib.orf.at/zib2/wolf/stories/259407/

January 13, 2008

Enabling/Disabling gnome-screensaver with a custom keyboard shortcut

Filed under: Uncategorized — th @ 2:54 am

I guess everyone is familiar with the screensaver starting up when in fact you didn’t want it to. Either while playing a game or while giving a presentation as one of my lecturers at university regularly did during this last term. The screensaver repeatedly came up and he had to use the laptop’s touchpad to get rid of it. I asked myself why he didn’t just disable it for the lecture and realized that it’s quite inconvenient to disable the screensaver in GNOME (I think the lecturer was using Xfce but nevermind). There’s no obvious other way than using the graphical interface for this (System/Preferences/Screensaver/Activate when idle). After some research I found the -i flag of gnome-screensaver-command which prevents the screensaver from starting up until termination. So what I did was writing a tiny PyGTK application which either starts gnome-screensaver-command -i or kills all processes called gnome-screensaver-command and displays a corresponding OnScreen-message for two seconds (screensaver on/screensaver off).

Debian package
gnome-toggle-screensaver_0.1-1_all.deb

SVN checkout
svn co http://svn.thammerl.interlinked.org/repos/projects/gnome-toggle-screensaver

In order to configure a keyboard shortcut for gnome-toggle-screensaver do the following after installation of the debian package:

  1. open gconf‐editor
  2. go to apps/metacity/keybinding_commands
  3. set the value for some key named command_x to “gnome‐toggle‐screensaver”
  4. go to apps/metacity/global_keybindings
  5. search for the key run_command_x where x corresponds to the x in the command_x key from step 3
  6. set the value of this key to the desired shortcut (i.e. <Alt>S)

Yes, this only works if you’re using metacity as your window manager. If you’re using another window manager you can use XBindKeys to configure a window manager independant keyboard shortcut.

September 20, 2007

Random Text Generator

Filed under: Uncategorized — th @ 3:57 pm

I implemented a Java library at hackday#003 which generates random texts after it has been trained with an arbitrary text corpus. If you are interested in the implementation details take a look at this webpage.

This is how a so called MarkovChain is instantiated:

import at.knallgrau.randomtext.*;

MarkovChain sentenceChain = new at.knallgrau.randomtext.MarkovChain(2, new SentenceLimiter(5));
MarkovChain lengthChain = new MarkovChain(2, new LengthLimiter(1000));

This is how a MarkovChain is “trained”:

MarkovChain chain = new MarkovChain(2);
chain.update(”give me two glasses of wine.”);
chain.update(”give me three bottles of beer.”);
chain.update(”give me two glasses of beer.”);
chain.update(”give me three bottles of wine.”);

This is how random text is generated from a trained MarkovChain:

String text = chain.generateRandomText();

I’m going to make the source code available in the next couple of days I’ve made the source code available even though the source is quite ugly (the api could be more elegant too) since hackday is all about getting something ready for a demo in less than seven hours. ;) You can check it out from my subversion repository:

svn co http://svn.thammerl.interlinked.org/repos/projects/randomtextgenerator randomtextgenerator

Download randomtextgenerator-1.0.jar

September 2, 2007

SMS Reader released

Filed under: Uncategorized — th @ 9:27 pm

At the last Knallgrau Hackday I’ve implemented the core components of a service which [ab]uses Google Calendar’s SMS event reminders as a rather cheap possibility of subscribing one’s cell phone to RSS/Atom feeds (disclaimer: I’ve stolen this idea from my friend and former colleague Ben Ferrari). Now this service is finally online: SMS Reader. Please forgive me for the poor graphics design. I was born with two left eyes. Also forgive me for the unhandy URL. No money, no DNS entry.

May 4, 2007

Let’s try and resize it

Filed under: Uncategorized — th @ 7:50 pm

That’s what working with the Java Swing GridBagLayout is like. The resize bug demonstrated in the flash animation was reported nearly eight years ago in java 1.2 and hasn’t been fixed until the time of this writing. Now that’s what I call agile development…

February 24, 2006

Bloglines’ subscription export != well formed XML

Filed under: Uncategorized — th @ 2:14 pm

Work today hasn’t been as much fun as it could have been. Having to deal with non-well formed xml data isn’t the exciting task you probably would expect it to be in the first place. I’m working on a simple Java class which gets a URL to a OPML document, parses it and returns the values of all occuring xmlUrl-attributes. An ungrateful task which you would assume shouldn’t take you any longer than half an hour. Unfortunately there are evil people on the other side of your internet connection who just decline to create valid opml or even well formed XML documents. Just take a look at this snippet from my Bloglines subscription export OPML document:

<outline xmlUrl=”http://twoday.tuwien.ac.at/A1/index.rdf”/> <outline xmlUrl=”http://derstandard.at/?page=rss&ressort=Uni”/> <outline xmlUrl=”http://www.tocotronic.de/RSS/tocotronic.rss”/> <outline xmlUrl=”http://rss.orf.at/fm4.xml”/>

Can you spot the damn character that ruined my afternoon? Beware, spoiler in the next paragraph.

It’s the charming little &-parameter-delimiter in the URL of derstandard.at which let’s my Xerces SAX-Parser refuse to do it’s job (creating a DOM Tree) because it insists on the &-character being replaced by an XML entity (http://www.w3.org/TR/REC-xml/#syntax). In this case this would be & or it’s numerical equivalent &.

I already notified them of this little but annoying inconformity and I’m anxious to see whether they’ll do something about it.

february 24th - update:

I got the following response from bloglines on the 22nd of february:

“Hello Thomas:

We appreciate that you have brought this to our attention. We have forwarded your information to the appropriate department for resolution, and regret any inconvenience.”

The issue is fixed by now. The ampersands are now escaped with their counterpart entity &.

February 17, 2006

Solving scrabbles using Aspell

Filed under: Uncategorized — th @ 10:24 pm

My friend Sperti is hosting a quiz-like game over at his weblog. He posts a question every friday night and additionally gives a number representing the position of a certain letter inside the answer string. Sperti is going to post eleven questions and if you’ve got all of them right you’ll be able to unscrabble the extracted letters to a word which will earn you an evening out in the viennese nightlife with the quizmaster himself paying for everything.

Inspiration enough for me to ensure I’m going to be this one lucky fella. So I thought about how my personal computer could ease the job. Unfortunately i came to the conclusion that I’d have to find the answers to the questions by myself but at least I found a computational way to do the unscrabbling of the letters by using GNU Aspell.

GNU Aspell is an open source spell checker which can be used independently or as a library like I did. I’ve written a command line tool in C which takes a sequence of letters as it’s argument, computes all possible permutations and matches each permutation against an Aspell dictionary. If the permutation matches a word in the dictionary it is written to the program’s stdout. It’s also possible to get guesses for “incomplete” scrabbles. This all is pretty straightforward but let me give you an example for each of those usecases anyway:

Thomas@thomas ~>unscrabble tmgicpnou computing Thomas@thomas ~>unscrabble -length 6 monm Mormon moment Munmro common Thomas@thomas ~>unscrabble -lang de chinakreme mechaniker

I suppose the first example doesn’t need any further explanation so let’s move on to the second one. The command line argument -length can be used in order to get guesses for an “incomplete” scrabble. In the example above we are searching for a word consisting of six characters whearas four of these characters are ‘m’, ‘m’, ‘o’ and ‘n’. Unscrabble gets suggestions from Aspell which focus lies on detecting spelling mistakes, not on solving scrabbles ;). Therefore the list of suggestions might not be complete. Aspell’s suggestion strategy is based on the Levenshtein distance and soundslike equivalents. Unscrabble filters all suggestions from Aspell that don’t meet the prior mentioned conditions and displays only those that do.

The third example demonstrates how to use non-english Aspell dictionaries. For that purpose it’s necessary to use the -lang option followed by the name of a valid installed dictionary. You can get a list of all installed Aspell dictionaries by executing the following command:

Thomas@thomas ~>aspell dump dicts de de_CH de_DE en en_CA en_CA-w-accents en_GB en_GB-w-accents en_US en_US-w-accents

These are the requirements for compiling the most valuable unix command line tool ever:

  • gcc
  • aspell
  • libaspell-dev

and this is how you do it:

Thomas@thomas ~>make unscrabble gcc -o unscrabble -laspell unscrabble.c

i suggest not to unscrabble any words consisting of more than eleven characters unless you’ve got a whooole lot of time. ;) getting suggestions for incomplete scrabbles is even more computationally intensive.

unscrabble.tar.gz (1,53kb)

January 1, 1970

Gaim rhymes with shame

Filed under: Uncategorized — th @ 1:00 am

Gaim Contact List

This is probably the dumbest reason imaginable to bring this blog back to life again after eight months of non-blogging…but anyhow…

While upgrading my Ubuntu system to Edgy Eft I did some other system administration. One thing that has been bothering me for quite some time now was that I couldn’t figure out how to see my own online status in my instant messaging client called Gaim. I just realized what a fool I’ve been to expect that kind of functionality if there are already several IM protocols inherently taking care of the issue! That’s what i’m told to do in the official faq section over at gaim.sourceforge.net:

How can I see my own status with Gaim?

Currently the only supported method to see your own status is to add yourself to your buddy list. This works with Aim, ICQ, Y!M, IRC, and some of the others, and is mimiced by gaim for MSN and Jabber.

So i’ve finally found a usecase for grouping my IM contacts as you can see in the upper left corner… ;)

Sidenote: The upgrade to Edgy Eft went terribly wrong. The X Server was crippled and wouldn’t come up when I tried to reboot. When I tried to install Dapper again the system hung up during the installation process. So I’m installing Breezy Badger again right now and will upgrade to Dapper afterwards like I did before all that trouble.
—–

Powered by WordPress