What is the most useful script you've written for everyday life? [closed]

Just wondering what little scripts/programs people here have written that helps one with his or her everyday life (aka not work related).

Anything goes, groundbreaking or not. For me right now, it's a small python script to calculate running pace given distance and time elapsed.


Solution 1:

My o key fell off on my laptop; so I wrote a program that replaces two 0 keystrokes within 200 MS of each other as an o, two 0 keystrokes within 700 MS of each other as a 0 and ignore the rest; so I could use my laptop before I get around to replacing the keyboard.

Wow; I didn't know this would be so popular :p

As for how - Microsoft exposes a nice little API feature called Hooks.

Using that hook; I was able to write a "filter" that did what I needed it to do (hint: if you return 1 with your callback windows will not process the keystroke).

The reason I know about this actually is not because I was writing a keylogger - but because I wrote a program smiler to Synergy a while ago.

And yes. I did write another program that swapped alpha-numeric keys with a random alpha-numeric key and yes; it was really funny :D

Solution 2:

I don't have the code any more, but possibly the most useful script I wrote was, believe it or not, in VBA. I had an annoying colleague who had such a short fuse that I referred to him as Cherry Bomb. He would often get mad when customers would call and then stand up and start ranting at me over the cubicle wall, killing my productivity and morale.

I always had Microsoft Excel open. When he would do this, I would alt-tab to Excel and there, on the toolbar, was a new icon with an image of a cherry bomb. I would discreetly click that ... and nothing would happen.

However, shortly after that I would get a phone call and would say something like "yeah, yeah, that sounds bad. I had better take a look." And then I would get up, apologize to the Cherry Bomb and walk away.

What happened is that we used NetWare and it had a primitive messaging system built in. When I clicked the button, a small VBA script would send out a NetWare message to my friends, telling them that the Cherry Bomb was at it again and would they please call me. He never figured it out :)

Solution 3:

A bash script called up so that if I'm in /a/very/deeply/nested/path/somewhere and I want to go "up" N directories, I can type up N:

#!/bin/bash
LIMIT=$1
P=$PWD
for ((i=1; i <= LIMIT; i++))
do
    P=$P/..
done
cd $P

For example:

/a/very/deeply/nested/path/somewhere> up 4
/a/very> 

NB by gmatt:

Working off the great work above, it can be extended to a back function by placing the following into your bashrc:

function up( )
{
LIMIT=$1
P=$PWD
for ((i=1; i <= LIMIT; i++))
do
    P=$P/..
done
cd $P
export MPWD=$P
}

function back( )
{
LIMIT=$1
P=$MPWD
for ((i=1; i <= LIMIT; i++))
do
    P=${P%/..}
done
cd $P
export MPWD=$P
}