Skip to content

Instantly share code, notes, and snippets.

@breun
breun / five_longest_classes_in_java_codebase.sh
Created March 19, 2010 21:16
Find the five longest class names in a Java codebase.
find . -name '*.java' -exec basename {} .java \; | awk '{ print length " " $0 }' | sort -n -r | head -n 5
@breun
breun / generate_password.sh
Created June 27, 2010 23:24
Generate a password of 10 random alphanumeric characters
#!/bin/sh
# Generate a string of 10 random alphanumeric characters
env LC_CTYPE=C tr -cd "[:alnum:]" < /dev/urandom | head -c 10
@breun
breun / couchdb-update.py
Created August 18, 2010 08:16
Update all documents from a view in CouchDB.
#!/usr/bin/env python
#
# This script updates a field for all documents in a view. Modify as needed.
#
# This script requires couchdbkit:
# $ sudo easy_install -U Couchdbkit
from couchdbkit import Server
import logging
@breun
breun / scrabble.groovy
Last active September 23, 2015 21:27
A Groovy Scrabble scorer based on the Scala scorer at http://gist.github.com/618308
#!/usr/bin/env groovy
/**
* A Groovy port of the Scala script at http://log4p.com/2010/10/09/scala-shellscripts/
*/
if (args.length < 1) {
println "usage: ./scrabble <filename>"
return
}
@breun
breun / euro_2012_hashtags.groovy
Created June 12, 2012 20:36
Print all possible Euro 2012 match hashtags (Dutch)
#!/usr/bin/env groovy
def countries = [
"Denemarken",
"Duitsland",
"Engeland",
"Frankrijk",
"Griekenland",
"Ierland",
"Italië",
@breun
breun / multibin.sh
Last active October 8, 2015 08:59
This script lists all commands that appear more than once in your $PATH. For of each command its locations and the number of occurrences are displayed.
#!/bin/bash
#
# This script lists all commands that appear more than once in your $PATH.
# For of each command its locations and the number of occurrences are displayed.
#
# Nils Breunese <[email protected]>, 2012.
for command in `compgen -c`
do
count=`which -a $command | wc -l | tr -d ' '`
@breun
breun / freak_out_sysadmin.pl
Created February 25, 2013 23:47
How to have fun with program names and freak out your sysadmin
$0 = "rm -rf /";
print "Press ENTER to exit\n";
<STDIN>;
@breun
breun / find_words.sh
Last active December 14, 2015 07:38
Search a list of words for all words with a certain length (here: 4) that can be formed from a list of characters (here: ['e','l','n','o','p','q']).
groovy -ne 'if (line.size() == 4 && line.toLowerCase().toList().sort().join() =~ /^e?l?n?o?p?q?$/) println line' /usr/share/dict/words
@breun
breun / timemachine_exclude_target_directories.sh
Last active August 29, 2015 14:05
Exclude Maven target directories from Time Machine backup
# Exclude all paths for directories named 'target' in the ~/Projects directory (which I use for my Maven projects)
# Sticky excludes (without -p and sudo) are not that useful, because 'mvn clean' removes the target directory
find ~/Projects -type d -name target | xargs sudo tmutil addexclusion -p
# List all items excluded by path
plutil -convert xml1 -o - /Library/Preferences/com.apple.TimeMachine.plist | xmllint -xpath /plist/dict/array[2] -
# List all items with sticky excludes
mdfind "com_apple_backup_excludeItem = com.apple.backupd"
@breun
breun / find_aliens.sh
Created March 18, 2015 10:19
What in my home directory is not owned by me?
#!/bin/sh
find ~ -not -user $USER -ls