5550

77
+55  Q:

## What is the most useful script you've written for everyday life?

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.

+6  A:

alias dir='ls -al' is my preferred favorite script.

eww... I ofter find myself wanting to go the other way...
You have to wonder why people start down voting answers to questions with a tag of subjective....what's the frickin' point?
Yes, this is critical :)
+10  A:

My .cmd backup script. It runs on my server every night, and names the backup files according the week day. A full week of backups has saved me (and my family) many times:

:: Backup args:
::   /V Verify? (yes/no)
::   /RS Removable storage? (yes/no)
::   /HC Hardware compression (on/off)
::   /M Backup type (normal/copy/differential/incremental/daily)
::   /L Log file type (f/s/n)
::   /D "Description"
::   /J "Job-name"
::   /F "File-name"

SETLOCAL

:: ensure that network drives are mounted
CALL C:\bat\configs\MapShares-home.cmd
echo on

set today=%DATE:~0,3%
if %today%==Mon set yesterday=0Sunday
if %today%==Tue set yesterday=1Monday
if %today%==Wed set yesterday=2Tuesday
if %today%==Thu set yesterday=3Wednesday
if %today%==Fri set yesterday=4Thursday
if %today%==Sat set yesterday=5Friday
if %today%==Sun set yesterday=6Saturday

set configsDir=%~dp0
set storePath=C:\mybackups

:: (eg: Monday C files)
set title=%yesterday% backup set

echo %DATE% %TIME% %title% > "%storePath%\%yesterday%_backup.log"

CALL BackupConfigs.bat

:: Create new BKF file
call C:\WINDOWS\system32\ntbackup.exe backup ^
"@%configsDir%\daily.bks" ^
/V:yes /R:no /RS:no /HC:off /M normal /L:s ^
/D "%title%" ^
/J "%title%.job" ^
/F "%storePath%\%yesterday%.bkf" ^
>> "%storePath%\%yesterday%_backup.log"

echo %DATE% %TIME% Completed >> "%storePath%\%yesterday%_backup.log"

copy "%storePath%\%yesterday%.bkf" "V:\Backups\NEPTUNE"

CALL C:\bat\clean-temps.bat

defrag -v C: > "%storePath%\%yesterday%_defrag.log"

:: display backup directories
start /D"C:\bat\Backups\" checkbkf.bat

ENDLOCAL

::pause


Some nice .cmd file tricks there. I knew you could use '^' to escape redirection and pipes, but I didn't know you could also use it as for line continuation. Cool :)
The world needs less .bat scripts, not more! :-)
And the corollary is that the world needs less Windows. Until then, this is the least common denominator. I share this script because zillions of people can use it, as is.
+2  A:

A small task-bar program that extracted every error-code constant out of a third-party JavaDoc and let me lookup the constant-name for a given error code. Plus, add in any conversions from HEX to decimal, etc.

This comes up a lot when working in the debugger--you get back the error code, but then tracking back the code to text is a huge pain. It's even more common when working with software that wraps native methods, OS calls, or COM... often times, the constants are copied straight out of an error header file with no additional context, repeated values, and no enumerations.

You do know about http://java.sun.com/javase/6/docs/api/constant-values.html, right?
Yes I am. Try searching this one for an error code that is reported using the HEX value. http://edndoc.esri.com/arcobjects/9.2/java/api/arcobjects/constant-values.html
Oh, and there are 8 different java doc libraries for this API... all of them with their own constant-values.html file.
+7  A:

A threaded HTML scraper to download all available subtitles for series/movies from a site which is a pain to use (you have to click like 4 times after a search to get to the download page, just to display more ads). Now I just put the search criteria and press download.

He'll share it, and the site would find out :). Better not to share sometimes...
... Share privately? =)
+9  A:

"backup.sh" that tars up the contents of a directory and sends it to my gmail account.

Now that is cool. Though I have no computers out of my tens that have smtp setup. Sadly.
+1 for sharing the code ;)
+54  A:

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."

http://msdn.microsoft.com/en-us/library/ms644959(VS.85).aspx#wh_keyboard_llhook

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

I might have thought of just typing on the exposed key-rest, but that's certainly an interesting way around it :)
I think this answer is pretty cool. Not that the others aren't, but this one is just...different. :)
I wnder why I didn't think f that... I'm having the same prblem... :-(
The enter key on my laptop fell off (due to my video game rage,) and there's no numpad Enter key. Can you help me?
@haoest: see those USB ports? Seen any USB keyboards?
This reminds me of this XKCD comic: http://xkcd.com/196/
HA! Y00u will n00t be able t00 type 00n a standard keyb00ard again with00ut retraining y00ur fingers! G0000d Luck!
yeah it dose take some adjusting. Man; I need a new laptop now. I figure I might just as well get a new one seeing as this is a three year piece of junk. Some remoting software (logmein) does not work with my app. So I have to copy+paste o's when I need them if I'm logged into a friends computer :p
The big question is how did you manage to write that program without using the letter 'o'?
I have a desktop too :)
eJames: Probably by using asc(111) or similar.
+8  A:
#! /bin/bash
# check to see if site is up
#   if it is, don't worry
#   if it's down, restart apache after get a process listing
#
# v.1 Warren M Myers - initial stab
#     31 Aug 06
#

ERRCOD='7'
WHEN=date +%d%b%y
REPT="~/psaux.$WHEN.txt" STARS='********************' curl -I http://www.shodor.org > /var/tmp/curlret.txt if [ "$?" = "$ERRCOD" ]; then # return was unable to connect to host: save ps -aux; mail report ps -aux >$REPT
echo $STARS echo 'curl return results' echo cat curlret.txt echo echo$STARS
echo 'ps -aux results'
cat $REPT echo echo$STARS
echo 'restarting apache'
/etc/init.d/apache2 restart
echo 'apache restarted'
echo
echo "ps -aux results saved in $REPT" fi rm -f /var/tmp/curlret.txt  +3 A: Various Shortcuts to "net start" and "net stop" commands so I can start and stop services without having to go into the Services MMC +7 A: Mass file renaming via drag&drop. Ages ago I've made a small VBScript that accepts a RegEx and replaces file names accordingly. You would simply drop a bunch of files or folders on it. I found that to be very useful throughout the years. gist.github.com/15824 (Beware, the comments are in German) Care to share the code? Seems silly to up vote a description sans code. The code would be a bit too much for the website. Maybe "small" was a bit of an understatement. It's 170 LOC. I could upload the script to somewhere and post the link here if you are interested. +1 A: A similar backup.sh for each project, that tars and gzips just the source, moves it into a snapshot directory and labels it with timestamp: project-mmddyy-hhmmss. Useful for coding between commits. +1 A: I had a version control script that would take a directory as an argument, and recursively copy all files to ../dirname/DATE/TIME/ Obviously it was a crappy way to do things, but it was handy before installing a real version control package. +4 A: A shell script to perform rotating backups using rsync. It also supports executing arbitrary child programs to support other pre-backup activities (downloading delicious bookmarks, for example). http://gist.github.com/6806 +1 A: Called assignIisSite_ToAppPool.js Really useful when you want to make sure that some resources are properly mapped. :) SetAppPool("W3SVC/1059997624/Root", "MyAppPool"); function SetAppPool(webId, appPoolName) { var providerObj=GetObject("winmgmts:/root/MicrosoftIISv2"); var vdirObj=providerObj.get("IIsWebVirtualDirSetting='" + webId + "'"); vdirObj.AppPoolId=appPoolName; vdirObj.Put_(); }  +2 A: A script that runs hourly to retrain my spam filters based two IMAP folder where span and ham are put. #!/bin/sh FNDIR="train-as-spam" FPDIR="train-as-ham" for dir in /home/*/.maildir do cd "${dir}"
USER=stat -c %U .

SRCDIR="${dir}/.${FNDIR}"
if [ ! -d ${SRCDIR} ]; then echo no "${SRCDIR}" directory
else
cd "${SRCDIR}/cur" ls -tr | while read file do if grep -q "^X-DSPAM" "${file}"; then
SOURCE="error"
else
SOURCE="corpus"
fi

dspam --user "${USER}" --class=spam --source="${SOURCE}" --deliver=innocent,spam --stdout < "${file}" > "../tmp/${file}"
mv "../tmp/${file}" "${dir}/new/${file%%:*}" && rm "${file}"
done
fi

SRCDIR="${dir}/.${FPDIR}"
if [ ! -d ${SRCDIR} ]; then echo no "${SRCDIR}" directory
else
cd "${SRCDIR}/cur" ls -tr | while read file do if grep -q "^X-DSPAM" "${file}"; then
SOURCE="error"
else
SOURCE="corpus"
fi

dspam --user "${USER}" --class=innocent --source="${SOURCE}" --deliver=innocent,spam --stdout < "${file}" > "../tmp/${file}"
mv "../tmp/${file}" "${dir}/new/${file%%:*}" && rm "${file}"
done
fi

done

+1  A:
#!/usr/bin/perl
use strict;
use utf8;
use Encode;
use File::Find;
binmode STDOUT, ':utf8';
sub orderly {
my ($x,$y) = @_{$a,$b};
if (my $z =$x <=> $y) {return$z}
$x = length$a;
$y = length$b;
my $z =$x < $y ?$x : $y; if (substr($a, 0, $z) eq substr($b, 0, $z)) { return$y <=> $x; } else { return$a cmp $b; } } my %conf = map +($_ => 0), split //, 'acsxL';
sub Stat {$conf{L} ? lstat : stat} my @dirs = (); while (defined ($_ = shift)) {
if ($_ eq "--") {push @dirs, @ARGV; last} elsif (/^-(.*)$/s) {
for (split //, $1) { if (!exists$conf{$_} or$conf{$_} = 1 and$conf{a} and $conf{s}) { print STDERR "$0 [-a] [-c] [-s] [-x] [-L] [--] ...\n";
exit 1;
}
}
}
else {push @dirs, $_} } s/\/*$//s for @dirs;  # */ SO has crappy syntax highlighting
@dirs = qw(.) unless @dirs;
my %spec = (follow => $conf{L}, no_chdir => 1); if ($conf{a}) {
$spec{wanted} = sub { Stat; my$s = -f _ ? -s _ : 0;
decode(utf8 => $File::Find::name) =~ /^\Q$dirs[0]\E\/?(.*)$/s; my @a = split /\//,$1;
for (unshift @a, $dirs[0]; @a; pop @a) {$_{join "/", @a} += $s; } }; } elsif ($conf{s}) {
$spec{wanted} = sub { Stat;$_{$dirs[0]} += -f _ ? -s _ : 0; }; } else {$spec{wanted} = sub {
Stat;
my $s = -f _ ? -s _ : 0; decode(utf8 =>$File::Find::name) =~ /^\Q$dirs[0]\E\/?(.*)$/s;
my @a = split /\//, $1; ! -d _ and pop @a; for (unshift @a,$dirs[0]; @a; pop @a) {
$_{join "/", @a} +=$s;
}
};
}
if ($conf{x}) {$spec{preprocess} = sub {
my $dev = (Stat$File::Find::dir)[0];
grep {$dev == (Stat "$File::Find::dir/$_")[0]} @_; }; } while (@dirs) { find(\%spec,$dirs[0] eq "" ? "/" : $dirs[0]);$_{""} += $_{$dirs[0]} if $conf{c}; shift @dirs; }$_{$_} < 1024 ** 1 ? printf "%s «%-6.6sB» %s\n",$_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 0),$_ :
$_{$_} < 1024 ** 2 ? printf "%s «%-6.6sK» %s\n", $_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 1), $_ :$_{$_} < 1024 ** 3 ? printf "%s «%-6.6sM» %s\n",$_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 2),$_ :
$_{$_} < 1024 ** 4 ? printf "%s «%-6.6sG» %s\n", $_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 3), $_ :$_{$_} < 1024 ** 5 ? printf "%s «%-6.6sT» %s\n",$_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 4),$_ :
$_{$_} < 1024 ** 6 ? printf "%s «%-6.6sP» %s\n", $_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 5), $_ :$_{$_} < 1024 ** 7 ? printf "%s «%-6.6sE» %s\n",$_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 6),$_ :
$_{$_} < 1024 ** 8 ? printf "%s «%-6.6sZ» %s\n", $_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 7), $_ : printf "%s «%-6.6sY» %s\n",$_{$_}, sprintf("%6.6f", "$_{$_}" / 1024 ** 8),$_
for grep {$_{$_} > 0} sort orderly keys %_;


I save it in ~/bin/dush, it acts as a sort of du -h/du | sort -n hybrid: sorts and gives human-readable sizes all at once. Very useful for finding what's taking up disk space.

In a similar vein,

#!/usr/bin/perl
$t = 1; %p = map {$_ => ($t *= 1024)} qw(K M G T P E Z Y);$t = 4707319808;
if (@ARGV) {
if (($_ = shift) =~ /^-*dvd/i) {$t = 4707319808}
elsif (/^-*cd[^w]*$/i) {$t = 737280000}
elsif (/^-*cd/i) {$t = 681984000} elsif (/^-*([\d.]+)([kmgtpezy])/i) {$t = $1 * ($p{"\U$2"} || 1)} elsif (/^-*([\d.]+)/) {$t = $1} else {unshift @ARGV,$_}
}
($q,$r, $s) = (0, ($ENV{COLUMNS} || 80) - 13, $t); while (<>) { chomp, stat; unless (-e _) { print STDERR "$_ does not exist\n";
next;
}
if (($s += -s _) >$t) {
$s &&$s < $t && printf "-%7s %s\n", sprintf("%2.3f%%", 100 * ($t - $s) /$t), $t -$s;
printf "-----------%d%*s\n", ++$q,$r, "-" x $r;$s = -s _;
}
printf "%8s %s\n",
sprintf("%3.3f%%", $s * 100 /$t),
/.{4}(.{$r})$/s ? "...$1" :$_;
}
$s &&$s < $t && printf "-%7s %s\n", sprintf("%2.3f%%", 100 * ($t - $s) /$t), $t -$s;


I save this as ~/bin/fit. When I'm archiving a bunch of files, I run ls | fit or ls | fit -cdrw to help determine if it'll fit on a DVD/CD/CDRW, and where to split them if they don't.

+5  A:

A Greasemonkey script to add a "press that button a lot" control box to an online game.

+2  A:

I use procmail to sort my incoming email to different folders. Because I have trouble remembering the procmailrc syntax, I use m4 as a preprocessor. Here's how my procmailrc begins (this isn't the script yet):

divert(-1)
changequote(<<, >>)
define(mailinglistrule,
<<:0:
* $2 Lists/$1
>>)
define(listdt, <<mailinglistrule($1,^Delivered-To:.*$2)>>)
define(listid, <<mailinglistrule($1,^List-Id:.*<$2>)>>)
divert# Generated from .procmailrc.m4 -- DO NOT EDIT


This defines two macros for mailing lists, so e.g. listdt(foo, [email protected]) expands to

:0:
* ^Delivered-To:.*[email protected]
Lists/foo


meaning that emails with a Delivered-To header containing [email protected] should be put in the Lists/foo folder. It also arranges the processed file to begin with a comment that warns me not to edit that file directly.

Now, frankly, m4 scares me: what if I accidentally redefine a macro and procmail starts discarding all my email, or something like that? That's why I have a script, which I call update-procmailrc, that shows me in diff format how my procmailrc is going to change. If the change is just a few lines and looks roughly like what I intended, I can happily approve it, but if there are huge changes to the file, I know to look at my edits more carefully.

#! /bin/sh

PROCMAILRC=.procmailrc
TMPNAM=.procmailrc.tmp.
cd $HOME umask 077 trap "rm -f$TMPNAM" 0

m4 < .procmailrc.m4 > $TMPNAM diff -u$PROCMAILRC $TMPNAM echo -n 'Is this acceptable? (y/N) ' read accept if [ -z "$accept" ]; then
accept=n
fi

if [ $accept = 'y' -o$accept = 'Y' ]; then
mv -f $TMPNAM$PROCMAILRC && \
chmod 400 $PROCMAILRC && \ echo "Created new$PROCMAILRC"
if [ "$?" -ne 0 ]; then echo "*** FAILED creating$PROCMAILRC"
fi
else
echo "Didn't update $PROCMAILRC" fi  The script hasn't yet prevented any email disasters, but it has made me less anxious about changing my procmailrc. +19 A: I have a Python script that automatically runs when I plug my digital camera in. It copies all of the pictures off the card on the camera, backs them up, and then uploads them to Flickr. The upload-to-Flickr piece comes from uploadr.py (which I can't take credit for). Here's the Python code for unloading the camera. It recurses through SRCDIR and names each image with the date & time before copying the images to DESTDIR. #!/usr/bin/python import os import string import time import shutil ################################################### __SRCDIR__ = "/mnt/camera" __DESTDIR__ = "/home/pictures/recent" ################################################### def cbwalk(arg, dirname, names): sdatetime = time.strftime("%y%m%d%H%M") for name in names: if string.lower(name[-3:]) in ("jpg", "mov"): srcfile = "%s/%s" % (dirname, name) destfile = "%s/%s_%s" % (__DESTDIR__, sdatetime, name) print destfile shutil.copyfile( srcfile, destfile) ################################################### if __name__ == "__main__": os.path.walk(__SRCDIR__, cbwalk, None)  Share the code, and I'll share an up vote :) This will work great until the day you forget those special pics you took the night before... How do you trigger the 'run on plug in' bit? +6 A: I'm a private pilot. I wrote a couple of scripts that obtain weather information for local airports from aviationweather.gov. They were useful for a quick answer to the question "Is today a good day to fly?" I hope for your passengers that your script will fail nicely if aviationweather.gov changes its layout and breaks your parser! +2 A: A script that reads a config file in the current dir, logs into an FTP account, and uploads all files that have changed since the last time it was run. Really handy for clients who use shared hosting, and FTP is my only option for file access. http://lucasoman.com/code/updater +3 A: I wrote a simple VB app that tracked which game numbers of Freecell I had played and successfully completed, and always launched it with a different seed. ....starting from 1.... Max game number is 65k. Rather sadly after more than 5 years I am still in only the hundreds. But at least I know I've never played the same hand twice! ** Postscript - it's the only VB app I've ever written. I ran screaming back to C++.... I'll have to dig deep to find it. Gotta be around here somewhere.... LOL @ the PS. :-) +1 A: I use a DOS program that errors out if it's past a certain date. I just looked at the batch file that it was using to start up and changed it so it would first change the date to 2000, then run the program. On the program's exit, it changed the date back to what it was before it was changed. +1 A: I wrote a cron job to grab the ip address of my dads router and ftp it to a secure location so when he needed help I could remote desktop in and fix his comp. That's also very useful if you have one of "those" parents. ;) It's useful, but why don't you use dyndns.org or similar services? Most routers support that out-of-the-box nowadays. Too bad if the net was broken :| I'd recommend dynamyc dns too, much simpler. +42 A: Super remote reset button. A rack of super special simulation hardware (backin the days when a room full of VME crates did less then your GPU) that a user on the other side of the world would crash in the early hours of the morning. It took an hour to get into the lab and through security. But we weren't allowed to connect to the super special controller or modify the hardware. The solution was an old DEC workstation with an epson dot matrix printer, tape a plastic ruler to the paper feed knob, position the printer near the reset button. Log in to the WS as a regular user (no root allowed, all external ports locked down), print a document with 24blank lines - which rotated the paper feed knob and the ruler pressed over the reset on the super special hardware. Fantastic story! Not sure whether to believe you or not ;) It was eventually replaced by a power switch relay connected to the DTR line on the serial port - but that required root access. And I should have said DEC WS because it was running Ultrix. Wow, the lengths we go to to get by security! Reminds me of this: http://thedailywtf.com/Articles/Open-Sesame.aspx If we had CD trays in those days it would have been an easier solution, +8 A: A perl script that scrapes my local Craigslist, by selected categories, in to a SQL DB which I can then query against. V2 of this updates the DB with a timer and alerts me if I have a match on any of the queries, basically providing me with a background agent for CL. +1 A: As a scheduled task, to copy any modified/new files from entire drive d: to backup drive g:, and to log the files copied. It helps me keep track of what I did when, as well. justdate is a small program to prints the date and time to the screen g: cd \drive_d d: cd \ type g:\backup_d.log >> g:\logs\backup_d.log echo ========================================== > g:\backup_d.log d:\mu\bmutil\justdate >> g:\backup_d.log xcopy /s /d /y /c . g:\drive_d >> g:\backup_d.log +2 A: A small application that left click (or double-click) every "X" ms for "Y" amount of time. No more need for that drinking bird to work at the nuclear power plant! ;) +1 A: For those of us who don't remember where we are on unix, or which SID we are using. Pop this in your .profile. function CD { unalias cd command cd "[email protected]" && PS1="\${ORACLE_SID}:$(hostname):$PWD> "
alias cd=CD
}
alias cd=CD

+2  A:

I got a script which extracts id3 tags encodes the songs newly in a certain format, and then adds them according to the tags to my music library.

300 lines of python. Mostly because lame isn't able to deal with tags in a nice fashion.

Heh. I've written this one, too. I wonder how many times this wheel has been reinvented.
+40  A:

On Windows XP, I have set an AT job to run this command daily in C:\

dir /s /b * > dirlist.txt


This lists the full path of all files on the C drive. Then whenever I need to find a file, I can use findstr. This beats using Windows Explorer Search since it allows regular expression matching on the entire path. For example:

findstr ".jpg" dirlist.txt
findstr /i /r "windows.*system32.*png$" dirlist.txt  This is a very fast solution to set up, and great if you find yourself with a fresh Windows install and no internet connection. If you need to search within certain file types for some pattern, first list all of the files you need to check, then search within them. For example, to find a Java or Python program that flips an image you could do this: findstr "\.java \.py" dirlist.txt > narrowlist.txt findstr /i /r /f:narrowlist.txt "flip.*image"  dude, what a great idea. This is exactly what the unix locate program does @Mark Which shows that even if you have to work with Windows, you can learn an awful lot of useful stuff from unix I made one of these scripts for my "Documents" folder, which I can never seem to keep organized :-) and there I was using Google Desktop search :D +1 A: I wrote a script for formatting C source files that automatically indents the code using an appropriate combination of tab and space characters, such that the file will appear correct regardless of what the tab setting on your editor is. Source code is here. +1 A: Well back in 2005 I used Gentoo Linux and I used a lot a small program called genlop to show me the history of what I've emerged (installed) on my gentoo box. Well to simplify my work I've written not a small python script but a large one, but at that time I just started using python:  #!/usr/bin/python ############################################## # Gentoo emerge status # # This script requires genlop, # # you can install it using emerge genlop. # # Milot Shala <[email protected]> # ############################################## import sys import os import time #colors color={} color["r"]="\x1b[31;01m" color["g"]="\x1b[32;01m" color["b"]="\x1b[34;01m" color["0"]="\x1b[0m" def r(txt): return color["r"]+txt+color["0"] def g(txt): return color["g"]+txt+color["0"] def b(txt): return color["b"]+txt+color["0"] # View Options def view_opt(): print print print g("full-info - View full information for emerged package") print g("cur - View current emerge") print g("hist - View history of emerged packages by day") print g("hist-all - View full list of history of emerged packages") print g("rsync - View rsync history") print g("time - View time for compiling a package") print g("time-unmerged - View time of unmerged packages") print command = raw_input(r("Press Enter to return to main ")) if command == '': c() program() else: c() program() # system command 'clear' def c(): os.system('clear') # Base program def program(): c() print g("Gentoo emerge status script") print ("---------------------------") print print ("1]") + g(" Enter options") print ("2]") + g(" View options") print ("3]") + g(" Exit") print command = input("[]> ") if command == 1: print print r("""First of all you must view options to know what to use, you can enter option name ( if you know any ) or type view-opt to view options.""") print time.sleep(2) command = raw_input(b("Option name: ")) if (command == 'view-opt' or command == 'VIEW-OPT'): view_opt() elif command == 'full-info': c() print g("Full information for a single package") print ("-------------------------------------") print print b("Enter package name") command=raw_input("> ") c() print g("Full information for package"), b(command) print ("-----------------------------------") print pack=['genlop -i '+command] pack_=" ".join(pack) os.system(pack_) print print r("Press Enter to return to main.") command=raw_input() if command == '': c() program() else: c() program() elif command == 'cur': if command == 'cur': c() print g("Current emerge session(s)") print ("-------------------------") print print b("Listing current emerge session(s)") print time.sleep(1) os.system('genlop -c') print print r("Press Enter to return to main.") command = raw_input() if (command == ''): c() program() else: c() program() elif command == 'hist': if command == 'hist': c() print g("History of merged packages") print ("---------------------------") print time.sleep(1) print b("Enter number of how many days ago you want to see the packages") command = raw_input("> ") c() print g("Packages merged "+b(command)+ g(" day(s) before")) print ("------------------------------------") pkg=['genlop --list --date '+command+' days ago'] pkg_=" ".join(pkg) os.system(pkg_) print print r("Press Enter to return to main.") command = raw_input() if command == '': c() program() else: c() program() elif command == 'hist-all': c() print g("Full history of merged individual packages") print ("--------------------------------------") print print b("Do you want to view individual package?") print r("YES/NO?") command = raw_input("> ") print if (command == 'yes' or command == 'YES'): print g("Enter package name") command = raw_input("> ") print pkg=['genlop -l | grep '+command+ ' | less'] pkg_=" ".join(pkg) os.system(pkg_) print print r("Press Enter to return to main") command = raw_input() if command == '': c() program() else: c() program() elif (command == 'no' or command == 'NO'): pkg=['genlop -l | less'] pkg_=" ".join(pkg) os.system(pkg_) print print r("Press Enter to return to main") command = raw_input() if command == '': c() program() else: c() program() else: c() program() elif command == 'rsync': print g("RSYNC updates") print print print print b("You can view rsynced time by year!") print r("Do you want this script to do it for you? (yes/no)") command = raw_input("> ") if (command == 'yes' or command == 'YES'): print print g("Enter year i.e"), b("2005") print command = raw_input("> ") rsync=['genlop -r | grep '+command+' | less'] rsync_=" ".join(rsync) os.system(rsync_) print print r("Press Enter to return to main.") c() program() elif (command == 'no' or command == 'NO'): os.system('genlop -r | less') print print r("Press Enter to return to main.") command = raw_input() if command == '': c() program() else: c() program() elif command == 'time': c() print g("Time of package compilation") print ("---------------------------") print print print b("Enter package name") pkg_name = raw_input("> ") pkg=['emerge '+pkg_name+' -p | genlop -p | less'] pkg_=" ".join(pkg) os.system(pkg_) print print r("Press Enter to return to main") time.sleep(2) command = raw_input() if command == '': c() program() else: c() program() elif command == 'time-unmerged': c() print g("Show when package(s) is/when is unmerged") print ("----------------------------------------") print print b("Enter package name: ") name = raw_input("> ") pkg=['genlop -u '+name] pkg_=" ".join(pkg) os.system(pkg_) print print r("Press Enter to return to main") time.sleep(2) command = raw_input() if command == '': c() program() else: c() program() else: print print r("Wrong Selection!") time.sleep(2) c() program() elif command == 2: view_opt() command = raw_input(r("Press Enter to return to main ")) if command == '': c() program() else: c() program() elif command == 3: print print b("Thank you for using this script") print time.sleep(1) sys.exit() else: print print r("Wrong Selection!") time.sleep(2) c() program() command = ("") program()  +1 A: A python script that does a filewalk and prints my directory tree sorted by disk usage. +2 A: The most useful? But there are so many... 1. d.cmd contains: @dir /ad /on 2. dd.cmd contains: @dir /a-d /on 3. x.cmd contains: @exit 4. s.cmd contains: @start . 5. sx.cmd contains: @start . & exit 6. ts.cmd contains the following, which allows me to properly connect to another machine's console session over RDP regardless of whether I'm on Vista SP1 or not. @echo off ver | find "6.0.6001" if ERRORLEVEL 0 if not errorlevel 1 (set TSCONS=admin) ELSE set TSCONS=console echo Issuing command: mstsc /%TSCONS% /v %1 start mstsc /%TSCONS% /v %1 (Sorry for the weird formatting, apparently you can't have more than one code sample per answer?) From a command prompt I'll navigate to where my VS solution file is, and then I'll want to open it, but I'm too lazy to type blah.sln and press enter. So I wrote sln.cmd: @echo off if not exist *.sln goto csproj for %%f in (*.sln) do start /max %%f goto end :csproj for %%f in (*.csproj) do start /max %%f goto end :end  So I just type sln and press enter and it opens the solution file, if any, in the current directory. I wrap things like pushd and popd in pd.cmd and pop.cmd. Mark, try indenting the code in the numbered enumeration by another 4 spaces, it gets displayed as code then. And use backticks (…) to mark inline code. I used to do that a lot too. Other programmers would sometimes make fun of my "two letter commands to do everything." +19 A: A few years ago I wrote a winforms app with the help of a few win32 api's to completely lock myself out of my computer for an hour so that it would force me to go and exercise. Because I was lazy? No... because I had a personal fitness goal. Sometimes you just need a little kick to get started :) I love this idea. will you share it? +10 A: A Greasemonkey script which removes obviously stupid[*] comments from gaming site Kotaku.com. [*] As identified by common spelling mistakes, all-caps writing, excessive use of "LOL" and similar heuristics. Cool. I feel like extracting the regexp's, and generate random statements consisting only of expressions matching one or more of them. +1 A: Anime CRC32 checksum: #!/usr/bin/python import sys, re, zlib c_null="^[[00;00m" c_red="^[[31;01m" c_green="^[[32;01m" def crc_checksum(filename): filedata = open(filename, "rb").read() sum = zlib.crc32(filedata) if sum < 0: sum &= 16**8-1 return "%.8X" %(sum) for file in sys.argv[1:]: sum = crc_checksum(file) try: dest_sum = re.split('[]', file)[-2] if sum == dest_sum: c_in = c_green else: c_in = c_red sfile = file.split(dest_sum) print "%s%s%s %s%s%s%s%s" % (c_in, sum, c_null, sfile[0], c_in, dest_sum, c_null, sfile[1]) except IndexError: print "%s %s" %(sum, file)  Could you provide some details about what this does? Basically anime tends to come with [23dsfa] as a checksum in the filename, this script I believe extract that value out of the filename and use it to checksum the file. +1 A: alias snoot='find . ! -path "*/.svn*" -print0 | xargs -0 egrep '  +2 A: A Quick and Dirty Python script that looked up the DNS for google.com every 5 seconds and beeped once if it succeeded and twice if it failed. I wrote this during a time when I had to live with a highly flaky home network. It allowed me to instantly know the state of the network even while I was head first under the desk across the room with both hands full of network cable and a flashlight in my mouth. 5 seconds? Must've gotten really annoying. Well yes, it drove me bats after 30 minutes or so. The idea was to have as close to real time feedback as possible. I could usually fix things in about 10 minutes. +2 A: MySQL backup. I made a Windows batch script that would create incremental backups of MySQL databases, create a fresh dump every day and back them up every 10 minutes on a remote server. It saved my ass countless times, especially in the countless situations where a client would call, yelling their head off that a record just "disappeared" from the database. I went "no problem, let's see what happened" because I also wrote a binary search script that would look for the last moment when a record was present in the database. From there it would be pretty easy to understand who "stole" it and why. You wouldn't imagine how useful these have been and I've been using them for almost 5 years. I wouldn't switch to anything else simply because they've been roughly tested and they're custom made, meaning they do exactly what I need and nothing more but I've tweaked them so much that it would be a snap to add extra functionalities. So, my "masterpiece" is a MySQL incremental backup + remote backup + logs search system for Windows. I also wrote a version for Linux but I've lost it somewhere, probably because it was only about 15 lines + a cron job instead of Windows' about 1,200 lines + two scheduled tasks. +34 A: 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 :) You know you are a programmer when you write a program to get out of an awkward social situation. Awesome! This is social engineering at its finest! +3 A: This, from a posting in my blog a few months ago, has gone from being an idea that I thought was cool to one of the best little hacks I've coughed up in recent memory. I quote it in full here: ================== I spend a lot of time in bash. For the uninitiated, bash is a system that you'll find on most unix machines and, thankfully, some windows and every Mac out there. At first blush, it's no more than a command-line interface, and therefore off the radar of most users who see such things as an anachronism they'd rather forget. I do nearly everything in bash. I READ MY EMAIL FROM A COMMAND LINE, which is why I eschew marked-up email. I navigate directories, edit files, engage in my daily source code checkout and delivery, search for files, search inside files, reboot my machine, and even occasionally browse web pages from the command line. bash is the heart and soul of my digital existence. The trouble is that I tend to have about 6 bash windows open at a time. At work today, I had one running a web server, another fiddling with my database, a third, fourth, and fifth editing different files, while a sixth was grinding away through my machine trying to record the names of every file on the system. Why? Because it's handy to be able to search through such an archive if you want to know where to find an object by filename. When you do this, you end up with lots of windows in your control bar named simply, "bash." This is fine if you only have one of them, but its agony when you have 6 or more.... and two dozen other things going on. I have three monitors under the simultaneous command of one keyboard/mouse pair and I still feel the need for more. Each of those windows has several bash terminals open. So I've plunked this together. First, place these lines in your .bash_profile:  export PROMPT_COMMAND='export TRIM=~/bin/trim.pl' export PS1="$\e]0;\TRIM\a$\$TRIM> "
trap 'CMD=history|~/bin/hist.pl;echo -en "\e]0;$TRIM>$CMD\007"' DEBUG


I went through and wrote dozens of paragraphs on how this all works and exactly why it is set up the way it is, but you're not really interested. Trust me. There is an entire chapter of a book in why I did "CMD=...; echo..." on that third line. Many people (including bluehost, where my other domain is hosted) are still using and old version of bash with major bugs in how it handles traps, so we're stuck with this. You can remove the CMD and replace it with $BASH_COMMAND if you are current on your bash version and feel like doing the research. Anyway, the first script I use is here. It creates a nice prompt that contains your machine name and directory, chopped down to a reasonable length:  ============trim.pl=========== #!/usr/bin/perl #It seems that my cygwin box doesn't have HOSTNAME available in the #environment - at least not to scripts - so I'm getting it elsewhere. open (IN, "/usr/bin/hostname|");$hostname = <IN>;
close (IN);
$hostname =~ /^([A-Za-z0-9-]*)/;$host_short = $1;$preamble = "..." if (length($ENV{"PWD"})>37);$ENV{"PWD"} =~ /(.{1,37}$)/;$path_short = $1; print "$host_short: $preamble$path_short";

==============================


There's a warning at the top of this blog post that you should read now before you start asking stupid questions like, "Why didn't you just use the HOSTNAME environment variable via @ENV?" Simple: Because that doesn't work for all the systems I tried it on.

Now for the really cool bit. Remember line 3 of the .bash_profile addition?

  trap 'CMD=history|~/bin/hist.pl;echo -en "\e]0;$TRIM>$CMD\007"' DEBUG


It's dumping the trim.pl script output in the same container as before, printing to both the command prompt and the window title, but this time it's adding the command that you just typed! This is why you don't want to be doing all of this in your .bashrc: any script you run (on my machine, man is one of them) will trigger this thing on every line. man's output gets seriously garbled by what we're doing here. We're not exactly playing nice with the terminal.

To grab the command you just typed, we take the bash's history and dice it up a bit:

                        ===========hist.pl============
#!/usr/bin/perl

while (<STDIN>)
{
$line =$_
}

chomp $line;$line =~ /^.{27}(.*)/;
print $1; ==============================  So now, I have a bazillion windows going and they say things like:  castro: /home/ronb blog Ron-D630: /C/ronb/rails/depot script/server Ron-D630: /C/ronb/rails/depot mysql -u ron -p Ron-D630: /C/ronb/rails/depot find . > /C/ronb/system.map Ron-D630: /C/ronb/rails/depot vi app/views/cart.html.erb Ron-D630: /C/perforce/depot/ p4 protect Ron-D630: /C/perforce/depot/ p4 sync -f Ron-D630: /C/perforce/depot/  From the happy little bar at the bottom of the screen, I can now tell which is which at a moment's glance. And because we've set PS1, as soon as a command finishes executing, the command name is replaced by just the output of trim.pl again. UPDATE (same day): This stuff (the .bash_profile entries) laid all kinds of hell on me when I tried it in my .bashrc. Your .bashrc is executed by non-interactive scripts whenever you invoke bash as a language. I hit this when I was trying to use man. All sorts of garbage (the complete text of my .bashrc, plus escape charecters) showed up at the top of the man page. I would suggest testing this gem with a quick 'man man' invocation at the command line once you get it all together. I guess it's time for me to pull the custom garbage out of my .bashrc and put it where it belongs... Incedentally, I found myself typing 'man trap' at one point in this process. Awesome post, thanks! +1 A: I have a batch file which establishes a VPN connection and then enters an infinite loop, pinging a machine on the other side of the connection every five minutes so that the VPN server doesn't drop the connection due to inactivity if I don't generate any traffic over that connection for a while. +2 A: A little script that monitors some popular websites for ads that match my skills and email me an email. +1 A: Best real-life script? Me: (Enters room) "Boss, I want a raise." Boss: (Offers chair from behind desk) "A raise? Please, take my job!" Then again, that may be the worst script! +33 A: 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 }  +1 Absolutely *f*'ing brilliant! I will be using this a *lot*! replace with this one-liner: p=$(printf "%${1}s" " "|sed 's/ /..\//g'); cd$p;
Why would you replace easy to read code with difficult to read code? Does your computer run more quickly if you have less less lines of source code?
I am on Mac and I cannot get the code working. Are you 100% sure that there should not be some quotes somewhere?
Thank you for this.
for mac see this: http://stackoverflow.com/questions/1328750/shell-script-that-goes-up-n-folders-in-the-file-system
@Masi: yes. Many, many quotes. "$1", "$P", "$PWD" all the way through and you will get on much better... gnud: replace my clean and clear code with garbage? No thanks. brilliant! I extended this to include a back method, so whenever you use up you can use back to easily move back and forth. To use it put this in your bashrc (sorry about shit formatting): function up( ){LIMIT=$1P=$PWDfor ((i=1; i <= LIMIT; i++))do P=$P/..donecd $Pexport MPWD=$P}function back( ){LIMIT=$1P=$MPWDfor ((i=1; i <= LIMIT; i++))do P=${P%/..}donecd$Pexport MPWD=$P} Great idea, but a minor point: wouldn't it be better located in .bash_profile since it's only applicable to interactive shells? hmm I won't lie to you my scripting ability is dubious at best, if .bash_profile is more appropriate then go for it. Should I change that in the note I wrote above? You could change it. Generally the difference is that .bash_profile is read once when you log in, while .bashrc is read every time you start a shell (which includes shell scripts which have no use for interactive aliases and functions). Most peoples' .bash_profile source their .bashrc as well, as noted here: http://stackoverflow.com/questions/415403/whats-the-difference-between-bashrc-bash-profile-and-environment +3 A: I use this as an autoloaded function. I can just type "mycd" and a list of directories appears which I frequently cd to. If I happen to know then number I can just say something like "mycd 2". To add a directory to the list you just type "mycd /tmp/foo/somedirectory". function mycd { MYCD=/tmp/mycd.txt touch${MYCD}

typeset -i x
typeset -i ITEM_NO
typeset -i i
x=0

if [[ -n "${1}" ]]; then if [[ -d "${1}" ]]; then
print "${1}" >>${MYCD}
sort -u ${MYCD} >${MYCD}.tmp
mv ${MYCD}.tmp${MYCD}
FOLDER=${1} else i=${1}
FOLDER=$(sed -n "${i}p" ${MYCD}) fi fi if [[ -z "${1}" ]]; then
print ""
cat ${MYCD} | while read f; do x=$(expr ${x} + 1) print "${x}. ${f}" done print "\nSelect #" read ITEM_NO FOLDER=$(sed -n "${ITEM_NO}p"${MYCD})
fi

if [[ -d "${FOLDER}" ]]; then cd${FOLDER}
fi

}

When I run "mycd", I get: "-bash: print: command not found". When I use "mycd /folder/", it does not add anything to /tmp/mycd.txt. Do I have some settings wrong?
Ah, yes, you might want to replace the 'print' statements with 'echo'. ;-)
@wzzrd How humiliating ;) Very cool function, @Ethan Post. Thank you for sharing!
+1  A:

I often use a MS Word macro that takes a source-code file, formats it in two columns of monospaced type on a landscape page, numbers the lines, and adds company header and footer info such as filename, print date, page number, and confidentiality statement.

Printing both sides of the page uses about 1/4 the paper as the equivalent lpr command. (Does anyone use lpr anymore???)

+1  A:

I've written a small shell script, tapt, for Debian based system. esp. Ubuntu. What it basically does is to post all your "apt-get" activities to your twitter account. It helps me to keep the track of what and when I've installed/remove programs in my Ubuntu system. I created a new Twitter account just for this and kept it private. Really useful. More information here: http://www.quicktweaks.com/tapt/

+1  A:

A simply Python script that converts line endings from Unix to Windows that I stuck in my system32 directory. It's been lost to the ages for a few months, now, but basically it'd convert a list of known text-based file types to Windows line endings, and you could specify which files to convert, or all files, for a wildcard list.

+2  A:

Not every day, but I did use XSLT script to create my wedding invitations (a Pages file for the inserts to the invite cards, and an HTML file for the address labels).

I've found a few uses for XSLT lately, and it feels like dabbling in black magic (in a good way).
+1  A:

A Rakefile in my downloads directory containing tasks that copy files from said directory to their respective media archives on external drives. Given my internet speed and storage capacity, it would take me hours out of every week to just copy across and re-name appropriately every piece of media that is downloaded (completely legally, I might add) by hellanzb.

Another very useful task in the same file logs into and scrapes IMDB for episode lists / discographies of all the media I have, and then checks NewzBin for reports that would fill any holes I have.

Combined, this means I have to do absolutely nothing, and in exchange, I wake up every morning with more media than I could possibly consume in that day sitting on my external hard drives.

Did I mention that this is all entirely above-board and legal? d-:

I'll probably merge this all into a sort of command-line media manager/player (farming things out to mplayer), and publish it on GitHub when I have the time.

+1  A:

[email protected] and [email protected] => modify the hosts file, to go through LAN or WAN addresses.

+4  A:

I like to store my photos in a directory based on the date the picture was taken. Therefore I wrote a program that would scan a memory card for pictures, create any folders on my hard disk that it needed to based on the dates of the pictures, then copy them in.

Care to add the script here? I would love this functionality, I do the same thing!
It's a c# app, not a script I'm afraid.
+5  A:

I used to work at a technology summer camp, and we had to compose these write-ups for each of the kids in the group at the end of the week, which they would then receive and take home as a keepsake. Usually, these consisted of a bunch of generic sentences, and one to two personalized sentences. I wrote a python script which constructed one of these write-ups out of a bank of canned sentences, and allowed the user to add a couple of personalized sentences in the middle. This saved a huge amount of time for me and other counselors I let in on the secret. Even though so much of it was automated, our write-ups still looked better than many of the 'honest' ones, because we could put more time into the personalized parts.

+1  A:

I have a batch file which runs every morning, which launches a browser with the tabs loaded to all the sites I want to check each day (Woot, Dilbert, Doonesbury, UserFriendly; seasonally, NY Mets scores and electoral-vote.com, plus a few websites that need to be visited regularly to keep membership active)

Does the script check the date and only open electoral-vote.com in election years? You'd earn my up-vote if so.
+1  A:

I wrote a file extraction tool to be used in Linux, that can extract about 20 different file formats and uses the file content, not the file name.

This tool got quite popular, I have a regular stream of people who download it from my blog. Get it here:

+1  A:

Sometimes I forget what are the most recent files I just created in a directory, but a ls command will just show every file in the directory, I just want a few most recent files so I put this in my .cshrc

 ls -l -t | awk 'NR<15{print $0}'  (Actually it is in a file called lt and in the .cshrc it is set with: alias lt '~/lt') So now lt will show me only a few files. Of course I don't know what platform you're on, but is there a reason you're not just using head or tail for this? Hmmmm good point... like ls -l -t > temp then do: head -15 temp. I guess I like awk allot and am not used to the more obvious unix commands other people use. How would you do it without creating a temporary file though? Pipe the output of the ls command into the head command just like you did with awk. (BTW, in case you don't already know, ls will allow you to combine the parameters into 1, so you can type ls -lt.) +2 A: VBS script to create a YYYY/YYYY-MM/YYYY-MM-DD file structure in my photos folder and move photos from my camera to the appropriate folder. +1 A: I wrote some lines of code to automatically tweak all things powertop suggests when I unplug my laptop and undo that if I plug the laptop back in. Maximum power, maximum efficiency, maximum convenience. +1 A: Running WinXP and I never seem to have time to kick off a defrag and wait for it to finish. So I wrote my own script to fire off XP's builtin defrag.exe and scheduled it to run nitely. The results are saved to a log file in C:\Temp for later review. @echo off GOTO :MAIN ########################################################### # # Reason: # This script runs the defrag utility. # # Suggestion: # Schedule this script to run daily (via schtasks) # # Example: # SCHTASKS /Create /SC DAILY /ST 03:00:00 # /TR \"C:\path\to\DAILY_DEFRAG.BAT" /TN "Daily Defrag of C Drive\" # # Example: # AT 03:00 /every:Su,M,T,W,Th,F,Sa C:\path\to\DAILY_DEFRAG.BAT # # Required OS: # Windows XP or Windows Server 2003 # # Required files: # DEFRAG.EXE # # ########################################################### :MAIN :: Output a listing of scheduled tasks SCHTASKS /QUERY /V > C:\temp\schtasks.out :: ***************************************************** :: * SITE SPECIFIC Program Parameters * :: ***************************************************** :: * Drive to defrag SET TARGET=C: :: * Log file SET LOGFILE=C:\temp\defrag.log :: ***************************************************** :: * No editable parameters below this line * :: ***************************************************** SETLOCAL :: Announce intentions echo. echo Beginning defragmentation of disk %TARGET% echo ---------------------------------------------- echo. for /f "tokens=1 delims=_" %%a in ('date /t') do set NOW=%%a for /f "tokens=1 delims=_" %%a in ('time /t') do set NOW=%NOW% %%a echo Start time: %NOW% :: Run the defrag utility C:\WINNT\SYSTEM32\defrag.exe %TARGET% -f -v > %LOGFILE% echo. for /f "tokens=1 delims=_" %%a in ('date /t') do set NOW=%%a for /f "tokens=1 delims=_" %%a in ('time /t') do set NOW=%NOW% %%a echo End time: %NOW% echo. echo ---------------------------------------------- echo Defrag complete. echo. :END  Just make sure you have nothing running when your defrag starts. I haven't used it in XP, but I found that, in earlier versions of Windows, the defrag utility would restart the entire defrag process *any* time there's a disk access by something else. (VERY annoying! :-( ) +1 A: Well an AutoHotkey script that make my life within reach of only a keyboard: 1. often used app, folder, etc. within one win+ combination. That often means activating the application if already launched, and else launch the application 2. "double-click" of ctrl to launch Launchy - which leads to a few keypresses from my not so often used apps 3. add a bunch of missing keyboard shortcuts in windows explorer (XP) such as create new folder, toggle hidden file/show file extension, Ctrl-Enter to open any file as text file in emacs, open command line window (cmd and cygwin shell) with the current path set, etc. etc. 4. Windows manipulation: move, resize, send to next monitor, max/minimize, toggle always on top, change transparency, etc etc. all with just key combinations 5. Misc such as hibernate, eject external drives, google any selected word (in any app where ctrl-c as copy works), shutdown timer, etc. etc. Everything with just one key combination This keyboard script just make me such a happy-camper; and it is in fact the major reason that I'm still using windows instead of linux as my primary platform since autohotkey only works on windows. +1 A: I suppose I should include my own answer to this, for completion's sake. I wrote a simple script that takes in the expenses of two people living together, and calculates which person owes the other money at the end of the month so that each person spent equally. I plan to extend it to store the categories of each expense and store them in a database. Sure, I could just use existing software...but where's the fun in that? Not very complex, sure, but as far as non-work related scripts that I use a lot at home, this one is the current leader. Hahaha, wish I'd read this before I posted. It's a lot of fun. +1 A: At some point in the distant past I decided to put all the files for my web host's public_html directory into a subversion repository. Then I wrote a script which: 1. Creates, mounts, and formats a RAM disk. 2. Exports the trunk of the repository into the RAM disk. 3. Calls rsync to upload any changed files from the RAM disk to my hosting provider. I use a public/private key pair to save me from typing my login information each time. 4. Unmounts the RAM disk. Thus, pushing updates from the repository to the server is literally a "one touch" operation. What is most satisfying about the script is that, initially, it was more of a shell scripting exercise than a Grand Project. However, it has probably saved me countless hours of work and makes the prospect of updating a website almost stress-free, maybe more than any other piece of software on my computer. +2 A: I suppose this depends on how you define useful, but my favorite little script is a variant on the *nix fortune program. See below, and you'll get the idea of what it does: telemachus ~$ haiku

January--
in other provinces,
plums blooming.
Issa


It doesn't really get anything done, but a nice haiku goes a long way. (I like how the colorizer decided to interpret the poem.) (Edit: If I really have to be useful, I'd say a script that allows a user to enter a US zipcode and get current weather and 0-3 days of forecast from Google.)

Glad you like the poem, but I can't take any credit for it (or the translation). It's from The Essential Haiku, edited by Robert Haas.
+1  A:

I wrote a python program to calculate my apartment's shared spending and output a neat little grid, with roommate as the columns and expense category as the row, along with how much money each roommate owed for rent, after adjusting for his contribution toward shared expenses. We'd been sharing this way for a while, but just adding up raw totals at the end of the month. I needed more granular control. With a maximum of eight keystrokes per line-item, this is way better than excel. I was sort of on a desperate quest to stop the monthly trend of one roommate spending 25% of our budget on beverages...

Nice, this definitely is cooler than a script I wrote for a similar purpose. I'm out of upvotes for the day, so I'll hit you back next time I can. :)
+1  A:

I wrote a simple Ruby script to help my wife and I when we were considering names for our first child. It generated all name combinations and checked the initials against a blacklist of initials I wanted to avoid, excluding any that didn't match my criteria. It felt like an appropriate thing for a nerdy dad to do and actually proved to be quite worthwhile and useful.

Other than that I've written a couple of Python scripts that serve as IRC bots which I use every day. One saves URLs, via regular expression matching, to delicious. Another serves as a simple IRC Twitter interface, allowing me to check my feed and post updates.

You'll also have a +1 from me when I can upvote again for that Ruby script.
+2  A:

I wrote a Python script that would go to all the web comics I read, and download any new comics. I just run that once a day, and there is no need to visit each site individually, just visit the /Comics/ Folder. ;)

Nice. You'll get a +1 too.
hmmm. If these are ad supported comics I would worry that you are not "paying" by taking the risk of seeing the ads :-)
@Matthew - I see your point, but I don't see why not looking at an advertisement is a moral/ethical issue. If that is the case, the authors of No-Script and pop-up blockers have a lot of explaining to do. ;)
I don't have any problem with pop-up blockers, because popups are an abusive way of displaying ads. It's not exactly a moral issue, more of a fairness issue. I use an adblocker on most sites, but turn it off for certain sites that I visit frequently and wish to support. Fetching the comics with a python script (and never seeing the site at all) feels over the line to me, but I could not tell you exactly where the line is.
+1  A:

A script to allow easy greping of ps results:

#!/usr/bin/php -f <?php $process =$argv[1]; echo shell_exec("ps -ef | grep $process | grep -v grep"); exit(0); +1 A: Wrote a little bash script that knew just enough about fonts to search through about 10k fonts and look for certain key words, in spite of their useless filenames but not return very many false positives. Took a while to run, about a minute on the dinky iMac, but it has saved me probably 50 hrs over the course of the last few years. +1 A: A: At my previous place of work office hours were ridiculous. It was a software company and my boss was sucked. He would give us work right around 5:30PM (right when it was time to go home) and made us finish the job until past 11:00PM (way past our ideal productive hours). Or he would find annoying problems in code that was still in progress. So I made a batch file and a script that would turn my computer OFF at a random time between 7:00PM and 8:00PM. It had a 1 minute timer just in case I would stay after hours and needed to abort the shutdown process. But I would leave my desk before 5:00PM so he couldn't find me to keep me if he wanted to dump crap around checkout time. If he came to my desk and see my computer on, he would think I was still around the pantry area or at the nearby minimart to grab some chips or something. But if it was off around that time, he would call my cell phone and tell me to get back to the office. I also scheduled the BIOS on my machine to turn my machine ON around 8:00AM or 9:00AM in case I felt lazy and wanted to stroll in around 10:00AM or 11:00AM. If I got caught walking to my desk he would ask "where have you been all morning?" And I would say "I was at a meeting with the marketing team." or "I was out getting breakfast." dumb dog +1 A: An alert box, on a random timer, guaranteed to pop-up at least once an hour to remind me to do some pushups. I used it when I was in the military. I also wrote architecture rules (http://architecturerules.org) for me and anyone else. +1 A: I like how git figures out when to use less, subversion doesn't have that feature so I want to easily get colored output in a pager. the cgrep alias lets me choose quickly. without it there are times I get raw color output. I also, when grepping through code, don't like to see certain results, like .svn ctags binary files grep -R sourcecodetext sourcedir | nosvn  Below is what I have in my config files cat .bash_profile alias nosvn="grep -v \"\.svn\|tags\|cscope\|Binary\"" alias less="less -R" alias diff="colordiff -u" alias cgrep="grep --color=always" export GREP_OPTIONS='--color=auto'  cat bin/gitdiffwrapper #!/bin/bash old_file=$1
tmp_file=$2 old_hex=$3
old_mode=$4 new_file=$5
new_mode=$6 colordiff -u$old_file $tmp_file  cat .gitconfig [diff] external =$HOME/bin/gitdiffwrapper


cat .subversion_config | grep ^diff-cmd

diff-cmd = /usr/bin/colordiff

+1  A:

Wrote a script to click my start button, then click it again in half a second, and repeat every 30 seconds.

Keeps me marked Online while at work, and I can get the real work done on my personal laptop right next to it. Not bogged down by work software.

Don't tell the boss :)

Ha ha ha, good stuff. +1 for both the honesty and dishonesty! :)
+1  A:
copy con c.bat
c:
cd\
cls
^Z

+1  A:

I wrote a script that ended up being used every day in my team. When I used to work for Intel we had an app that talked to an access database to grab a dump of register information (I worked on validating chipsets). It would take this information (from a SQL query) and dump it into a CSV file, HTML file, and an Excel file. The whole process took almost 2 hours. No joke. No idea why it took so long. We would start it up an hour before lunch, go to lunch, and then come back.

I thought that there had to be a better way of doing this. I talked to the team that maintained the registry database and got the SQL code from them. I then wrote a perl script that grabbed the data and outputted it into CSV, HTML, and Excel formats. Runtime? Around 1-2 seconds. A great speed improvement.

I also wrote a few scripts while I was on deployment in Iraq in 2006 (I served in the National Guard for 9 years - got out in December). We used this old app called ULLS-G (Unit Level Logistics System - Ground) that was written in ADA and originally ran on DOS. They hacked it enough to where it would run on Windows XP in a command shell. This system didn't have a mouse interface. Everything was via keyboard and it had NO batch functionality. So let's say you wanted to print out licenses for all vehicle operators? Well... we had 150 soldiers in our unit so it took a LONG time. Let's say everyone got qualified on a new vehicle and you wanted to add it to everyone's operator qualifications? You had to do it one by one.

I was able to find an ODBC driver for the SAGE database (what ULLS-G used) and so I wrote perl scripts that were able to talk to the SAGE database. So things that took over an hour, now took only a few seconds. I also used my scripts and the driver for reporting. We had to report all information up to battalion every morning. Other units would write the information in by hand every morning. I whipped up an Excel macro that talked used the same driver and talked to the SAGE database and updated the Excel spreadsheet that way. It's the most complicated and only Excel macro I've ever written. It paid off because they awarded me the Army Commendation Medal. So yeah, I got a medal in the military for writing perl scripts :) How many can say that? ;)