133

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.

3
  • I've seen some really cool work related ones, but not as many "everyday life" related scripts. Then again, if something at work is ruining your life and you fixed it with a neat script then who am I to judge?
    – Kyle Walsh
    Oct 9, 2008 at 18:30
  • 11
    One of those gem questions that makes stack overflow worth while. Any guideline that suggests it be closed shouldn't be there, any mod who voted to close it shouldn't be one.
    – Bill K
    Nov 22, 2016 at 7:28
  • This is one one for me: github.com/codeforester/base. This framework has increased my productivity as an SRE/DevOps person by leaps and bounds, while increasing team cohesiveness and collaboration. Jun 7, 2020 at 15:57

78 Answers 78

117

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

10
  • 1
    I might have thought of just typing on the exposed key-rest, but that's certainly an interesting way around it :)
    – warren
    Oct 9, 2008 at 17:02
  • 2
    I wnder why I didn't think f that... I'm having the same prblem... :-(
    – asterite
    Oct 9, 2008 at 17:30
  • 1
    This reminds me of this XKCD comic: xkcd.com/196
    – JesperE
    Oct 9, 2008 at 18:17
  • 59
    HA! Y00u will n00t be able t00 type 00n a standard keyb00ard again with00ut retraining y00ur fingers! G0000d Luck!
    – Doug L.
    Oct 29, 2008 at 4:00
  • 107
    The big question is how did you manage to write that program without using the letter 'o'?
    – e.James
    Jan 19, 2009 at 7:38
114

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 :)

3
  • 96
    You know you are a programmer when you write a program to get out of an awkward social situation.
    – Cadoo
    Feb 19, 2009 at 4:50
  • 7
    Awesome! This is social engineering at its finest!
    – Beska
    Mar 17, 2009 at 21:02
  • 1
    Let's hope Cherry Bomb does not use StackOverflow :)
    – Pedro Luz
    Jan 14, 2017 at 17:54
94

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
}
17
  • 4
    +1 Absolutely f'ing brilliant! I will be using this a lot!
    – wzzrd
    Jan 30, 2009 at 22:00
  • 12
    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?
    – Beska
    Mar 17, 2009 at 21:00
  • 3
    gnud: replace my clean and clear code with garbage? No thanks.
    – foxdonut
    Nov 14, 2009 at 13:32
  • 3
    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=$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 }
    – ldog
    Jun 17, 2010 at 23:55
  • 2
    am i crazy? how the hell does this work? cd in a script will cd there but when the script exists, you're back in the same/original directory! does my bash work different than all of yours?
    – johnnyB
    Dec 3, 2013 at 18:06
67

Super remote reset button.
A rack of super special simulation hardware (backin the days when a room full of VME crates did less than 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.

5
  • Fantastic story! Not sure whether to believe you or not ;) Oct 9, 2008 at 18:34
  • 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. Oct 9, 2008 at 19:16
  • Wow, the lengths we go to to get by security! Oct 23, 2008 at 23:18
  • 1
    Reminds me of this: thedailywtf.com/Articles/Open-Sesame.aspx
    – rjmunro
    Jan 5, 2009 at 18:05
  • 5
    If we had CD trays in those days it would have been an easier solution, Jan 7, 2009 at 21:41
63

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"
5
  • 8
    dude, what a great idea.
    – Epaga
    Oct 10, 2008 at 10:17
  • 11
    This is exactly what the unix locate program does
    – Mark Baker
    Oct 13, 2008 at 12:21
  • 4
    @Mark Which shows that even if you have to work with Windows, you can learn an awful lot of useful stuff from unix
    – Liam
    Oct 16, 2008 at 8:46
  • 1
    I made one of these scripts for my "Documents" folder, which I can never seem to keep organized :-)
    – sep332
    Nov 17, 2008 at 21:12
  • 1
    and there I was using Google Desktop search :D
    – Ian G
    Mar 17, 2009 at 20:50
38

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)
5
  • Share the code, and I'll share an up vote :)
    – Even Mien
    Oct 10, 2008 at 5:37
  • 41
    This will work great until the day you forget those special pics you took the night before...
    – Ed Guiness
    Nov 7, 2008 at 12:23
  • The full thing is actually a two-step process. The first step dumps things off the camera & renames them. The second step has a prompt asking if you want to upload to Flickr. That's more because uploading kills my bandwidth than because I'm worried about what I'm uploading.
    – Mark Biek
    Dec 30, 2008 at 1:48
  • 5
    How do you trigger the 'run on plug in' bit?
    – ijw
    Sep 2, 2009 at 12:27
  • @ijw For Unix, see here: unix.stackexchange.com/questions/28548/… - windows: superuser.com/questions/219401/…
    – Chris
    May 14, 2013 at 3:57
32

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 :)

0
16

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. ;)

3
  • hmmm. If these are ad supported comics I would worry that you are not "paying" by taking the risk of seeing the ads :-) May 13, 2010 at 19:27
  • 2
    @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. ;) May 13, 2010 at 21:34
  • 1
    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. May 19, 2010 at 15:24
14

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)
::   /R Restrict access to owner? (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

3
  • 2
    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 :) Oct 9, 2008 at 17:57
  • The world needs less .bat scripts, not more! :-)
    – JesperE
    Oct 9, 2008 at 18:07
  • 2
    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.
    – Chris Noe
    Oct 9, 2008 at 21:07
14

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

2
  • Now that is cool. Though I have no computers out of my tens that have smtp setup. Sadly.
    – mxcl
    Oct 24, 2008 at 0:49
  • Could we have the code please?
    – Kostas
    May 17, 2018 at 4:22
14

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? ;)

13

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

2
  • I hope for your passengers that your script will fail nicely if aviationweather.gov changes its layout and breaks your parser!
    – MatthieuP
    Mar 24, 2009 at 10:08
  • 1
    Could you please share the script?
    – JJD
    Oct 8, 2011 at 23:09
12

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.

1
  • 6
    Cool. I feel like extracting the regexp's, and generate random statements consisting only of expressions matching one or more of them.
    – gnud
    Feb 26, 2009 at 23:41
11

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

3
  • 4
    eww... I ofter find myself wanting to go the other way...
    – chills42
    Oct 9, 2008 at 18:33
  • 1
    You have to wonder why people start down voting answers to questions with a tag of subjective....what's the frickin' point? Oct 9, 2008 at 18:40
  • Yes, this is critical :)
    – Nick
    Mar 26, 2009 at 0:42
11

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.

1
  • 2
    He'll share it, and the site would find out :). Better not to share sometimes... Oct 15, 2008 at 1:58
11

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.

8

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)

3
  • Seems silly to up vote a description sans code.
    – Chris Noe
    Oct 9, 2008 at 17:04
  • The code would be a bit too much for the website. Maybe "small" was a bit of an understatement. It's 170 LOC.
    – Tomalak
    Oct 9, 2008 at 17:09
  • I could upload the script to somewhere and post the link here if you are interested.
    – Tomalak
    Oct 9, 2008 at 17:12
8

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.

2
  • 5 seconds? Must've gotten really annoying. Jun 18, 2010 at 0:35
  • 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. Jun 22, 2010 at 4:04
8

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.

0
8

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

7

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

0
7

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.

0
6
#! /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
6

A little script that monitors some popular websites for ads that match my skills and email me an email.

6

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

}
3
  • 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? Mar 25, 2009 at 6:11
  • Ah, yes, you might want to replace the 'print' statements with 'echo'. ;-)
    – wzzrd
    Mar 27, 2009 at 9:27
  • @wzzrd How humiliating ;) Very cool function, @Ethan Post. Thank you for sharing! Mar 28, 2009 at 20:09
5

Various Shortcuts to "net start" and "net stop" commands so I can start and stop services without having to go into the Services MMC

5

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.

3
  • Care to add the script here? I would love this functionality, I do the same thing!
    – Pharaun
    Jul 13, 2010 at 15:05
  • It's a c# app, not a script I'm afraid.
    – Valerion
    Jul 21, 2010 at 16:23
  • Do you use the exif information stored in the photos? Could you please share the script?
    – JJD
    Oct 8, 2011 at 23:12
5

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 :)

1
  • Ha ha ha, good stuff. +1 for both the honesty and dishonesty! :)
    – Kyle Walsh
    Nov 20, 2009 at 9:13
4

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

4

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! ;)

Not the answer you're looking for? Browse other questions tagged or ask your own question.