Hammer for every occassion

August 2, 2009

WTWTF

Filed under: hehehe — iceteajunkie @ 20:59

You probably read Daily WTF on, uh, daily basis.

This article caught my eye for longer than usual. If you haven’t read it, go ahead and read it (but don’t read the comments!). If you don’t want to read it, here’s the meat — someone changed:

int main (int argc, char **argv)
{
  int x;
  char data_string[15];
  ...
  x = 2;
  strcpy(data_string,"data data data");
  ...
}

to:

int main (int argc, char **argv)
{
  int x = 2;
  char data_string[15] = "data data data";
  ...
}

Good? Bad? Is that WTF we were looking for? Is that even WTF? Or perhaps there’s more than one WTF in the whole article? The comment thread under the article is already five pages big, and wild theories and misconceptions are flying around.

(more…)

May 26, 2009

Keyword searches vs delicious

Filed under: shiny! — iceteajunkie @ 01:03
Tags: , , ,

I’m writing about it as there’s surprisingly little info out there about this very useful feature of del.icio.us Firefox addon.

You probably know about Firefox “quick search” feature. Right click any search editbox, select add a keyword for this search, type in some keyword, save. From now on, if you enter keyword foo in Firefox’ address bar, it would use the search form assigned to this keyword with your foo. Dead easy, and very useful (and shame on you, if you didn’t know about this useful feature :).

The way it works behind the scenes, is that this feature is available for all GET forms. Such forms, redirect you to an URL that contain your search query as a parameter. All you need to do, is to add a bookmark in Firefox, that would have a %s in the URL, in place of your parameter, and a keyword. Once you have done that, Firefox will trigger on entering the keyword as a first thing in the address bar, grab the URL from the bookmark, substitute rest of entered text for %s in the URL, and visit the URL created that way. Firefox isn’t particular about this substitution, so you can define a search that will trigger on t, have http://twitter.com/%s as the address, to give you:

t makumba -> http://twitter.com/makumba

And now, cue in del.icio.us Firefox addon. Apart from being generally awesome, giving you a convinient interface to your del.icio.us bookmarks collection, it also allows you to save quicksearches. This way, any Firefox that you’re using that has this addon, will become equipped with your favourite quicksearches. Useful? You bet.

All quicksearches must be tagged with shortcut:foo tag on del.icio.us. This acts as a hint to the addon, that this bookmark should have a foo keyword active on the Firefox side of things. You can either import your old quicksearches, and then tag them with appropiate shortcut: tags, or just use add a keyword for this search in Delicious option, from the right-click menu. If you want to see what quicksearches I’m using, take a look here.

And with that useful thing in place, you can go back to the wonderful world of empty bookmark folder.

May 17, 2009

*sproing*

Filed under: whacked together — iceteajunkie @ 18:48
Tags: , ,

Trampolina,

aka solution to the problem that only I had.

Trampolina was written to solve a problem of mine: two people, two computers on the same network. One of those people find interesting article on the web, and wants to share it with the other person. Now, any sane person would just use email or IM to send the URL over. That was the case for me as well, but I’ve noticed that every time I need to launch GMail, or Adium — they were never around when needed. Of course I could have just train myself to have them always open, but I wanted to write some small and funny Python webapp… and I did.

This “small and funny” application is Trampolina. Small web application that serves only one purpose — LIFO stack of URLs. Here’s how Alice and Bob, our favorite IT demonstrators can use it:

  • Trampolina is installed on
    http://home-nas:9099/
  • Alice and Bob are sitting in front of their computers, next to each other, browsing the Web furiously.
  • Alice finds amazing article in Wikipedia:
    http://en.wikipedia.org/wiki/African_swallow
  • Alice visits:

    http://home-nas:9099/push?url=http://en.wikipedia.org/wiki/African_swallow

    As it would be rather peculiar to remember such complicated URL, Alice uses small bookmarklet for that purpose.

  • Alice pokes Bob who sits next to her.
  • Bob goes to:
    http://home-nas:9099/pop
  • Bob ends up knowing way too much about African swallows…

If either Alice or Bob wants to revisit some URL, backlog of them can be browsed at:
http://home-nas:9099/list

If the distance between Alice and Bob doesn’t allow for convenient poking, there’s an RSS that B can follow:
http://home-nas:9099/rss

Download

Here.

(more…)

April 28, 2009

GMail cheatsheet

Filed under: whacked together — iceteajunkie @ 23:27
Tags: , , ,

If you’re using GMail, and you’d like to do more stuff with it, without moving your hand over to your mouse/trackball/pointing device of choice, here’s little something to you.

GMail cheatsheet

Print it, put it up somewhere close to your display, use, not abuse. Made using only the freshest and juiciest organic ingredients, including fabulous VIM cheat sheet.

I’ve originally written about that handy cheatsheet here. And kudos to all you people that said “Hey, that reminds me of those Word Perfect keyboard listings!”. Yes, you’re old :D

Allmighty Spark vs. Terminal App

Filed under: bashed my head against — iceteajunkie @ 22:54
Tags: , , ,

No, it’s not about Transformers :)

Spark is something that is not needed in normal operating systems, that use customizable window managers — a keyboard shortcuts manager. That is, it will sit in background, intercept keyboard events, and do stuff. What kind of stuff? Well, it depends on how you configure it. It can run arbitrary commands, Applescripts, open documents, change system settings — nothing too fancy, but it has one major advantage, it works flawlessly, without trying to impose any extra philosophy on you.¹ You press something on your keyboard, and stuff happens. Simple, eh?

Around the same time I’ve discovered Spark, I’ve also decided to ditch iTerm. While generally awesome, it has one major disadvantage — it’s slow. It got way better over time, from completely unusable, to quite usable. Problem is, I end up with large terminals. And that’s still the moment when iTerm hiccups, which results in 1,5-3s delay for screen redraws, be it screen switching, or Vim redrawing its window. Terminal.app, this blank and uninteresting application that came together with the system didn’t have any problems like that, so I decided I’ll give it a try.

Basic set of customizations was easy to do. Proper colors (white-on-black instead of default eye-burning black-on-white) and proper font. Being used to iTerm, I wanted Terminal.app to mimic it at least a bit. First goal: make Cmd+Left/Right switch tabs. That was relatively easy — I’ve asked Spark to make a application-specific keybinding (one that will work only in Terminal.app) to click a menu item for me (Window → Select Previous Tab). Yes, that was way too easy.

Next goal was to have specific profiles of terminal bound to keyboard shortcuts. That is, ability to press Cmd+h for a new tab, with ssh host1 launched inside, Cmd+p for a new tab with ssh host2… you get the idea.  And here’s where problems started. The requested action for such keybind was to:

  • open a new tab
  • exec ssh host

Sounds Applescript-ish, right? I’ve opened script editor, pointed it at Terminal… only to discover that there’s no Applescript interface for ‘open a new tab’. Apparently, tabs are kind of fancy addition in OSX 10.5, and users should be happy that those made it in. No whining. Allright, one Google search later I found a twisted way of telling Terminal that it should launch a new tab — simulate a keystroke (Cmd-t). Good. One extra line and we’re set. Script worked from both command line and Spark config window. There.

…but it failed to work when bound to a key. What the…? I’ve poked around, asked on the forum, and it turned out that simulating a keystroke in a script that is used in Spark is not a good idea. Sigh. Next attempt was to simulate keystrokes with Spark. Just: cmd+t,e,x,e… Yeah, that worked. Assuming I’ve set the delay between key presses to something more than 5ms. If it was lower, some keypresses were getting lost. So allright, 6ms delay, and it works. I press the key, new tab launches… and hey, just like in a cheap hacker movie, characters slowly appear…

Here’s a bit of Applescript I’ve finally ended up with next day:

tell application "Terminal" to activate
tell application "System Events"
	click menu item ¬
		"default" in menu "New Tab" of menu item ¬
		"New Tab" in menu "Shell" of menu bar item ¬
		"Shell" in menu bar 1 of process "Terminal"
end tell
tell application "Terminal" to do script "clear; exec ssh myawesome.host" in first window

default is the name of Terminal.app setting (the one from Settings tab of Terminal’s preferences). Last line script (“clear; exec ssh myawesome.host“) is simply the set of commands to execute in newly created tab.

¹ Hey, I like Quicksilver. I really do. I just don’t use it, because I don’t really find a need for its fancy features.

April 26, 2009

DART – OSX widget for all Dubliners

Filed under: whacked together — iceteajunkie @ 19:36
Tags: , , , ,

If you:

  • live in Dublin and use DART trains;
  • use Mac OSX

then you might be interested in this little widget.

dart1 dart2

In short: it will show you upcoming departures for selected DART station. I’ve written about this thing previously on iceteajunkie: here and here, visit those posts to get more details. Or just try this thing :)

urlinfo.pl – get information about URLs (for irssi)

Filed under: whacked together — iceteajunkie @ 19:20
Tags: , ,

Here’s a little script I’ve written some time ago for Irssi. I’ve only found it recently on an old HDD, removed the dust, cleaned it up, added some functionality — and hey, it’s still useful :) There was a script that inspired me to write this one, but I can’t put my finger on its name.

How it works:

Once you load this script, it should react to URLs that appear on both channel and private chats.

single url

For each url spotted, this script will go, fetch the page, parse it, and display its title tag — which hopefully will server as a meaningful description. Urlinfo caches this information for some time, so next time it sees this URL, you should get the description much faster. The description will also be marked with different “bullet”.

cached url

If there’s more than one URL on the same line, you should get a description for all of them, one per line.

multiline urlinfo

How to use it:

  • download the file from here;
  • put it in your ~/.irssi/scripts directory;
  • ask Irssi to load it:
    /script load urlinfo

Gotchas:

  • if you need to go through proxy, set its address in the usual Unix style, via http_proxy enviroment variable;
  • if a page requests some kind of auth or cookie, this script won’t be able to provide them;
  • if fetching a page takes longer than 3s, script will time out and present you with an error message;
  • some webpages don’t set their <title> to anything descriptive — there’s hardly anything urlinfo can do about that.

Settings:

If you don’t want urlinfo to describe your URLs, say:

/set urlinfo_describe_own OFF

If you want to change the time for which fetched description is considered “fresh”, say:

/set urlinfo_validity_time <time in seconds>

By default, it should be 2 hours (7200s).

April 23, 2009

はじめまして

Filed under: meta — iceteajunkie @ 00:06

Welcome to my toolbox.

It’s way too late tonight for me to post anything long and decent, so you might just want to read what’s this blog is going to be about.

Blog at WordPress.com.