home

code snippets

important disclaimers

by language

java
perl
C
C#
bash
ruby
python
AWK
CSS
javascript (browser)
javascript (node)
Miscellaneous

java


Luhn

An implementation of the Luhn check digit algorithm.
Useful for validating credit card numbers.
Usage: Edit Luhn.java.
View on GitHub

perl


fcpool-api-fetch

Fetches data from FCPool's JSON API given a user's API key.
Reads the API key from either a file or the command line.
Update: This service appears to be shut down.
Usage: fcpool-api-fetch <api-key>
View on GitHub

d2pool-api-fetch

Fetches data from ftc.d2.cc's JSON API given a user's API key.
Functions similarly to fcpool-api-fetch, but uses HTTPS.
Update: This service appears to be shut down.
Usage: d2pool-api-fetch <api-key>
View on GitHub

wtf-urban

Uses Urban Dictionary's API to find definitions matching the query word.
Inspired by NetBSD's 'wtf' acronym-expanding script. Now a full perl module!
Usage: wtf-urban <word> [-l number]
View on GitHub

grayscale

Grayscales a given image and stores it as "grayscale.png," all using ImageMagick.
Usage: grayscale <image>
View on GitHub

randomimage

Generates a pseudorandom image using perl's rand() and ImageMagick.
If dimensions are not provided, a 500x500 image is generated.
Usage: randomimage [WIDTHxHEIGHT]
View on GitHub

nycdoe-fetch-attendance

Checks the NYC DOE XML API for daily attendance statistics for a given school.
Update: This service appears to be shut down.
Usage: nycdoe-fetch-attendance <"school name" | DBN>
View on GitHub

mk-qrcode

Generates a QR code image based upon textual user input.
Uses Imager::QRCode.
Usage: mk-qrcode <module size> <text>
View on GitHub

twitter-fortune-bot

Uses the Twitter REST API (1.1) to tweet fortunes from the "fortune" utility.
Important: You must add your own application/API keys to your environment.
For an example, see robot_fortune on Twitter.
Usage: twitter-fortune-bot
View on GitHub

magnet-to-torrent

Converts magnet links to torrent files using magnet2torrent.com.
Important: Bulk transactions through this script may not be appreciated by magnet2torrent's owners.
Update: This service has changed, and this script may no longer work.
Usage: magnet-to-torrent <'magnet link'>
View on GitHub

puush-scraper

Scrapes images and other files off of puush using trial-and-error.
Uses MIME headers to detect the correct file extension, defaulting to ".other" if not a text file or common image.
Update: puush appears to be using a new URL schema, and has been IP banning clients that use this script.
Usage: puush-scraper <number of files>
View on GitHub

fetch-math-finals

Fetches PDFs of previous mathematics finals for the given course from UMD's MathNet Test Bank.
Capable of grabbing finals from MATH, AMSC, and STAT courses.
Update: UMD has migrated its database to Google Drive. This script no longer works.
Usage: fetch-math-finals <course code>
View on GitHub

hexchat-gmb-nowplaying

A HexChat plugin that interfaces with gmusicbrowser via DBus.
Grabs information about the current song and ACTIONs it to the channel.
Requires Net::DBus.
Usage: /gmb-nowplaying
View on GitHub

hexchat-rainbow

A HexChat plugin that rainbowifies text.
Usage: /rb <text>
View on GitHub

hexchat-homoglyph

A HexChat plugin that converts text into visually similar homoglyphs.
Usage: /hg <text>
View on GitHub

hexchat-spacing

A HexChat plugin that spaces text out.
Usage: /sp <text>
View on GitHub

hexchat-america

A HexChat plugin that makes text red, white, and blue.
Usage: /america <text>
View on GitHub

hexchat-ezfmt

A HexChat plugin that provides basic text formatting.
Usage: /fmt *italics*, _underline_, and +bold+
View on GitHub

hexchat-fullwidth

A HexChat plugin that provides fullwidth text conversion.
Usage: /fw <text>
View on GitHub

hexchat-latex

A HexChat plugin that provides LaTeX symbol substitution.
Usage: \forall x \in \mathbb{R}
View on GitHub

hexchat-clap

A HexChat plugin that emphasizes👏your👏point👏.
Usage: /clap <text>
View on GitHub

verhoeff

A table implementation of the Verhoeff check digit algorithm.
Can be used to validate a numerical string or generate a check digit for an existing one.
Usage: verhoeff <validate | generate> <number>
View on GitHub

damm

A table implementation of the Damm check digit algorithm.
Can be used to validate a numerical string or generate a check digit for an existing one.
Usage: damm <validate | generate> <number>
View on GitHub

upc

A Universal Product Code (UPC) check digit validator.
Usage: upc <upc>
View on GitHub

sedol

A Stock Exchange Daily Official List (SEDOL) ID check digit validator.
Usage: sedol <sedol id>
View on GitHub

issn

An International Standard Serial Number (ISSN) check digit validator.
Usage: issn <issn>
View on GitHub

aba-rtn

An ABA Routing Transit Number (RTN) check digit validator.
Usage: aba-rtn <rtn>
View on GitHub

vin

A North American Vehicle Identificarion Number (VIN) check digit validator.
Usage: vin <vin>
View on GitHub

C


rot13

A tiny C99 implementation of the ROT13 Caesarian cipher.
Reads text from standard input.
Usage: rot13
View on GitHub

mersenne

A C99 implementation of the "Mersenne Twist" pseudorandom number generator.
Usage: Edit mersenne.c.
View on GitHub

mesg

A quick and dirty popup box for Batch scripts on Windows.
Usage: mesg.exe <message> [title].
View on GitHub

perm

A small utility for obtaining the permission bits of a file on Linux/Unix systems.
Outputs both standard string notation (i.e. 'rwxrwxrwx') and octal notation (i.e. '755').
Usage: perm <-s|-n <file>>
View on GitHub

battstat

Outputs system battery information obtained through sysfs.
Usage: battstat
View on GitHub

cond

A dumb conditional checker that makes asking for user confirmation simple.
Usage: cond [message]
Example: if cond "Continue?" ; then echo "Continuing..." ; fi
View on GitHub

eject

A minor nuisance, copied from the (discontinued) nuisances project.
Ejects disks (or just opens the drive) randomly and repeatedly. Relies on the Windows API.
Usage: eject.exe
View on GitHub

locks

A minor nuisance, copied from the (discontinued) nuisances project.
Randomly activates various control and modifier keys repeatedly. Relies on the Windows API.
Usage: locks.exe
View on GitHub

bf

A small C program that converts Brainfuck source files into C source files.
Uses a 30,000 byte stack, like the original implementation.
Usage: bf <input.bf> <output.c>
View on GitHub

tss

A tiny screenshot program.
Uses Xlib to dump the screen and libpng to save it as a PNG.
Usage: tss <filename>
View on GitHub

mntinfo

Gets information about the given filesystem from /etc/mtab and statvfs(3).
The output is formatted to ease parsing with grep and awk.
Usage: mntinfo <fs name>
Example: mntinfo /dev/sda1 | grep 'f_bsize' | awk '{ print $2 }'
View on GitHub

jellybean_trigger*

Monitors a Jellybean Button using ALSA's libesd.
When pressed, executes the supplied command (and arguments).
Modified from Rogach's Piano Pedal Driver (blog post).
Usage: jellybean_trigger <command [arg ...]>
Example: jellybean_trigger echo "click!"
View on GitHub

fstrings

A "fast", naive implementation of the strings utility.
Doesn't care about executable formats, has no dependencies.
Usage: fstrings [-n size] [file]
Example: fstrings -n 15 /bin/ls
View on GitHub

C# (.NET)


Netflix Player

Plays Netflix in an application separate from a standard web browser for performance.
Released into the public domain.
Usage: NetflixPlayer.exe
View on GitHub

bash


collapse

Collapses the given directory into its parent directory.
Usage: collapse <directory>
View on GitHub

robot-ftp

Crawls a given list of IPs, FTPing into them and leaving a message.
Usage: robot-ftp <IP file> <message file>
View on GitHub

read-qrcode

Reads the provided QR image, outputting its comments.
Usage: read-qrcode <image>
View on GitHub

git-aliases

A set of aliases for common git SCM commands.
To install, either copy the git-aliases file into your shell's profile or include it with a command like source /path/to/git-aliases.
Usage: Call any of the aliases.
View on GitHub

pathconfusion

A minor nuisance, copied from the (discontinued) nuisances project.
Messes with the user's $PATH, placing fake programs or wiping the $PATH altogether.
Usage: pathconfusion
View on GitHub

cskel

Generate a skeleton C file containing a main function and some common includes.
Not very useful, except for quickly testing an idea.
Usage: cskel [filename]
Example: vim `cskel test` # opens test.c in vim.
View on GitHub

jskel

cskel, but for java skeleton files.
Usage: jskel [filename]
Example: vim `jskel test` # opens test.java in vim.
View on GitHub

haste

A tiny script for posting files/standard input on Hastebin.
Lighter than haste-client, and more versatile than its recommended shell alternative.
Update: This script no longer works.
Usage: haste [file]
Example: my_program | haste.sh # or haste myfile.
View on GitHub

upload

Attempt to upload a file to a few different online filesharing services in sequence.
Currently tries pomf.se and teknik.io before bailing out.
Usage: upload <file>
View on GitHub

sscc

Attempt to take a fullscreen or selection screenshot by cascading through common screenshot utilities.
Currently tries gnome-screenshot and scrot before bailing out.
Usage: sscc [-s] <file>
View on GitHub

imgs2pdf

Converts a directory of images to a single PDF document.
Uses convert from ImageMagick.
Usage: imgs2pdf <directory> <output.pdf>
View on GitHub

flac2mp3

Converts FLAC files into MP3s in bulk.
Uses ffmpeg or avconv to perform the conversions.
Usage: flac2mp3 [-sdvh] [-j jobs] [directory]
View on GitHub

poomf*

Upload to sr.ht and teknik.io.
Heavily modified from Joe Schillinger's poomf.sh (now uguu).
Usage: poomf <-i | -f | -s | -u <file> | -h>
View on GitHub

play

Plays a URL or file, leveraging youtube-dl and livestreamer if installed.
Usage: play <file or URL>
View on GitHub

mp3art

Adds album artwork to MP3s in bulk.
Usage: mp3art [-svh] [-f artfile] [-j jobs] [directory]
View on GitHub

flacart

Adds album artwork to FLACs in bulk.
Usage: flacart [-svh] [-f artfile] [-j jobs] [directory]
View on GitHub

mdmath

A basic preprocessor for LaTeX math equations in Markdown.
Reads LaTeX math formatting between @@...@@, converting it into embedded images.
latex.codecogs.com is used to perform the LaTeX to image conversion.
Known problems: Multiple blocks on the same line won't work (thanks, sed).
LaTeX commands that begin with an escape character will also not work (like \texttt).
Usage: mdmath <file> > output.md
View on GitHub

notify

Notifies the user with a popup message in X.
Does so by cascading through various notification programs.
Currently supports xmessage, zenity, and notify-send.
Usage: notify <message>
View on GitHub

radio

Stream various radio stations, identified by callsign.
Stations are loaded from ~/.radiorc. Example here.
Usage: radio <station | list>
View on GitHub

rip

Quick rip an audio CD into a specified format using abcde.
Usage: rip <flac | mp3>
View on GitHub

xontop

Adds or removes the 'above' property from an X11 window.
Usage: xontop [-b | -h] # -b removes the property
View on GitHub

tal

Stream This American Life by episode number.
Usage: tal <episode #>
View on GitHub

pid2xid

Prints the X Window ID (xid) associated with a process ID.
Known problem: xwininfo is stupid and may not be reporting correct window IDs.
Usage: pid2xid <pid>
View on GitHub

watch-thunderbird

Watch a Thunderbird profile for new emails, running a command whenever a new one appears.
Known problems: "New email" events are guesses based on inbox writes.
Only works when the user only has one profile.
Usage: watch-thunderbird <cmd>
View on GitHub

normalize-gifs

Normalize the supplied GIFs to the resolution specified by DIMS.
Usage: normalize-gifs <gifs ...>
Example: DIMS=500x500 normalize-gifs 1.gif 2.gif 3.gif
View on GitHub

git-fetch-pr

Fetch and check out a pull request from GitHub.
Usage: git-fetch-pr <PR #>
Example: git-fetch-pr 123
View on GitHub

clocbadge

Turns a cloc(1) linecount into a pretty badge.
Usage: clocbadge <FILE|DIR> ...
Example: clocbadge src/ test/
View on GitHub

fftitle

Adds a centered title to the first 10 seconds of a video.
Usage: fftitle <input> <output> <title>
Example: fftitle my_video.mp4 my_video_titled.mp4 "my title"
View on GitHub

fftimelapse

Turns a video into a (soundless) 10x timelapse.
Usage: fftimelapse <input> <output>
Example: fftimelapse my_video.mp4 my_fast_video.mp4
View on GitHub

ffnicegif

Create a compact GIF from an input file.
Usage: ffnicegif <input> <output>
Example: ffnicegif my_video.mp4 my_gif.gif
View on GitHub

git-move-commits

Move the last N commits on the current Git branch to a new branch.
Usage: git move-commits <branch> [# of commits]
Example: give move-commits foo-feature 2
View on GitHub

ruby


git-contrib

Generates CONTRIBUTORS files for git repositories.
Capable of generating Markdown, CSV, and plain text.
Usage: git-contrib [--markdown | --csv]
View on GitHub

grabzit-screenshot

Takes a screenshot of a given website and saves it to the given file.
Uses Grabzit's API to do so.
Spoiler: Grabzit's API sucks and only takes thumbnails without a paid account. Don't use it.
Usage: grabzit-screenshot <url> <file>
View on GitHub

twitter-github-bot

A dumb Sinatra-based server that listens for repo release callbacks from GitHub.
Upon receiving an (authenticated) post, sends a digest to twitter.
For an example, see woodrufw on Twitter.
Usage: twitter-github-bot
View on GitHub

smtp-spoof-ruby

A line-by-line translation of the smtp-spoof python script.
Usage: smtp-spoof-ruby
View on GitHub

git-https2ssh

An awful script that haphazardly converts HTTPS remotes in git repositories into SSH remotes.
Only works half the time, and isn't very smart. Don't use it.
Usage: git-https2ssh
View on GitHub

cloud2butt-irc

A tiny Cinch bot that matches messages containing 'cloud' and substitutes all 'cloud's for 'butt's.
Inspired by the similar 'Cloud To Butt Plus' Chrome plugin.
Usage: cloud2butt-irc <irc.someserver.net> <'#chan1,#chan2,...'>
View on GitHub

haiku-critic

Another tiny Cinch bot that makes sure every message is in the form of a 5-7-5 haiku.
If the message does not match the syntax 5 // 7 // 5, the user is kicked.
Usage: haiku-critic <irc.someserver.net> <'#chan1,#chan2...'>
View on GitHub

xdcc*†

An Cinch XDCC file fetcher, modified from Mahdi Bchetnia's xdcc.
Released into the public domain.
Update: This script is old and buggy. Use the version linked instead.
Usage: xdcc <irc.someserver.net> <bot_name> <pack_number> [-c channel] [-d directory]
View on GitHub

ibip-check

A Cinch bot that scans a channel for IBIP compliant bots and reports information about them.
Usage: ibip-check <irc.someserver.net> <'#channel'>
View on GitHub

phishbot

A Cinch bot and control script that spawn a bunch of phishing bots that look like 'NickServ'.
When messaged privately, each bot reports the contents of the message back to a designated channel.
Usage: run # should be edited to change server/channels
View on GitHub

socketdump

Dumps a file into a socket, base64 encoded and headed by a hash and name.
Useful for quickly shooting data between two machines.
Complemented by socketslurp.
Usage: socketdump <port> <file>
View on GitHub

socketslurp

Reads a base64 encoded file from a socket, validating it using a SHA1 hash.
Useful for quickly shooting data between two machines.
Complemented by socketdump.
Usage: socketslurp <hostname> <port>
View on GitHub

image-glitch

'Glitch' an image by compositing it over itself at various coordinates and with various operations.
Creates the appearance of a corrupted image without damaging the file's integrity.
To glitch multple images together, see images-glitch.
Usage: image-glitch <image> [glitch level]
View on GitHub

images-glitch

'Glitch' multiple images together by repeatedly compositing them at various coordinates and with various operations.
Creates the appearance of a corrupted image without damaging the file's integrity.
To glitch only a single image, see image-glitch.
Usage: images-glitch <glitch level> <file1 file2 [file3 ...]>
View on GitHub

image-bork

Bork an image by repeatedly applying various filters and effects to it.
Creates the appearance of a corrupted image without damaging the file's integrity.
Usage: image-bork <image> [bork level]
View on GitHub

alexa500

Scrapes the Alexa.com 'top sites' ranking for the 500 most trafficked websites.
Uses Nokogiri and dumps the output to stdout.
Usage: alexa500 > output
View on GitHub

fortune500

Scrapes the Fortune 500 companies from uspages.com for their company websites.
Uses Nokogiri and dumps the output to stdout.
Usage: fortune500 > output
View on GitHub

validate_sites

Reads a newline-delimited stream of website addresses from stdin, testing each's markup validity with the Nu HTML Validator.
Uses vnu.jar and formats the output as <site> <warning count> <error count>.
Usage: cat sites | validate_sites > results
View on GitHub

nypd-crime-data

Fetches aggregated crime data from each NYPD precinct in PDF format.
Usage: nypd-crime-data
View on GitHub

image-artifact

Exacerbate artifacts in an image by repeatedly opening and writing it at varying low JPEG qualities.
Creates the appearance of a corrupted image without damaging the file's integrity.
Usage: image-artifact <image> <count>
View on GitHub

sdate

Prints today's Eternal September date in asctime format.
Inspired by (and much shorter than) the original sdate.
Usage: sdate
View on GitHub

email-fwd

A quick and dirty raw email forwarder.
Reads addresses and credentials from ~/.email-fwd. Example config here.
Usage: email-fwd
View on GitHub

umd-dining-balance

Fetch UMD dining plan balance data for a given student, by Directory ID.
Usage: umd-dining-balance <username> <password>
View on GitHub

umd-incident-logs

Fetch UMD crime and incident logs for the given month and year and dump them as JSON.
Usage: umd-incident-logs <month> <year>
View on GitHub

umd-arrest-ledger

Fetch UMD arrest records for the given year and dump them as JSON.
Usage: umd-arrest-ledger <year>
View on GitHub

sms

Send SMS/MMS messages using SMTP gateways provided by cellular companies.
Supports most large (US) cellular providers and reads from stdin.
Reads SMTP credentials and information from ~/.smsrc. Example config here.
Important: Your email provider may not appreciate the volume of mail produced by this script.
Usage: sms <phone number>
View on GitHub

uspatent

Fetches a filed US patent by number in PDF format.
Usage: uspatent <patent number>
View on GitHub

canvas-grades

Get a student's current term grades from Canvas.
Tested on UMD ELMS. Requires an access token (/profile/settings).
Usage: canvas-grades
View on GitHub

albumart

Fetch an album's cover art using Last.fm's search API.
Only retrieves large and extralarge images.
Images are saved as cover.png in $CWD.
Usage: albumart <query>
View on GitHub

liferea-yt-feed

Adds a YouTube channel to Liferea.
Works with both old (/user/) and new (/channel/)-style YouTube channels.
Important: This script uses liferea-add-feed, which is known to segfault on some versions of Liferea.
Usage: liferea-yt-feed <channel url>
View on GitHub

newsbeuter-yt-feed

Adds a YouTube channel to newsbeuter.
Works with both old (/user/) and new (/channel/)-style YouTube channels.
Usage: newsbeuter-yt-feed <channel url>
View on GitHub

ssqdb

A tiny static quote DB, inspired by QDB.
Usage: ssqdb </path/to/quotes.txt> [output directory] [options]
View on GitHub

ffmpeg-mosaic

Composes a list of videos into an NxM "mosaic" of specified dimensions.
Usage: ffmpeg-mosaic [--throttle] <dim> <NxM> <output> <file1 file2 ...>
Example: ffmpeg-mosaic 1920x1080 2x2 mosaic.mp4 source{1..4}.mp4
View on GitHub

gif-length-groups

Given N GIFs, compose them into random groups such that each group has the given total length.
Then, combine each group of GIFs into a single a single large GIF and save it.
Usage: gif-length-groups [-n <groups>] [-l <len>] [-i <len>] [-d <dir>] <gifs ...>
Example: gif-length-groups -l 60 -d groups *.gif
View on GitHub

giphy-fetch

Fetch animated GIFs from Giphy and save them to a directory.
Usage: giphy-fetch [--directory <dir>] <query>
Example: giphy-fetch --directory dogs "cute dogs"
View on GitHub

forecast

Fetch the weather forecast from Wunderground.
Usage: forecast <query>
Example: forecast washington dc
View on GitHub

rubyvm-dump

Dumps a Ruby script as a compiled sequence of (YARV) instructions.
Usage: rubyvm-dump [--marshal] <file>
Example: rubyvm-dump.rb my-script
View on GitHub

git-gem-release-tag

Tags, builds, and pushes a new RubyGem based on a gemspec in $PWD.
Usage: git-gem-release-tag [--dry-run]
Example: git-gem-release-tag
View on GitHub

msmtp

A tiny terrible SMTP server that pipes emails into a given command.
Usage: [sudo] msmtp <cmd>
Example: msmtp 'cat'
View on GitHub

git-lint-commit

A small Git commit message linter.
Usage: [sudo] git-lint-commit [commit|-]
Example: git-lint-commit HEAD~1
View on GitHub

python


smtp-spoof

Spoofs SMTP transactions with raw sockets.
Allows the user to send email from any address (but not any IP).
Usage: smtp-spoof
View on GitHub

panix-numbers

Get Panix dialup numbers for a given area code.
Numbers are scraped from Panix's public numbers.
Usage: panix-numbers <area code>
View on GitHub

pandora-mpv*

Stream a Pandora station into mpv.
Uses Pithos to acquire a stream and Lars Gustäbel's python-mpv to control mpv.
Pandora credentials are read from the environment as PANDORA_EMAIL and PANDORA_PASSWORD.
Usage: pandora-mpv ['station'] # uses QuickMix by default
View on GitHub

reddit-mpv*

Stream a subreddit into mpv.
Uses reddit's RSS API to acquire links and Lars Gustäbel's python-mpv to control mpv.
RSS feeds are parsed with feedparser.
Usage: reddit-mpv <subreddit>
Example: reddit-mpv videos # /r/videos
View on GitHub

AWK


linecheck

Checks each line in each provided file for length.
If the length exceeds 80 characters, spits out a warning for that line.
Usage: linecheck <file1 file2 ...>
View on GitHub

awkbot

A tiny IRC bot that shows that (GNU) AWK can be used as a general-purpose language.
Currently only responds to .bots, but can be easily extended.
Usage: awkbot <nick> <server> <chan1,chan2,...>
View on GitHub

CSS


stylish-deepdark-hack

A stylish style to fix input and textarea elements that Firefox's DeepDark theme makes invisible or difficult to see.
Usage: Install by URL or by copying into stylish.
View on GitHub

javascript (browser)


gsearch-neutralizer

Removes the onmousedown event from URLs in Google Search results, preventing rewrites.
Compatible with Greasemonkey; install from Greasy Fork here.
View on GitHub

javascript (node)


webshot-screenshot

Takes a screenshot of a given website and saves it to the given file.
Uses node-webshot to do so.
Usage: webshot-screenshot.js <url> <file>
View on GitHub

Miscellaneous


homebrew.mxcl.smbd

A basic property list file for using launchd on Homebrew's Samba formula.
Now merged with the actual Samba formula, and therefore no longer needed in stand-alone form.
Usage: Install homebrew.mxcl.smbdist to a directory watched by launchd.
View on GitHub