Skip to content

Instantly share code, notes, and snippets.

@hfs
hfs / rnd
Created February 23, 2014 20:16
Generate a 4-byte integer random number
#!/bin/sh
od -An -t uL -N4 /dev/random | tr -d ' '
@hfs
hfs / build.sbt
Created March 12, 2014 11:40
Separate integration tests in a Play! 2.2.2 project
import sbt._
// Enable integration tests:
// - put sources in src/it/java or src/it/scala
// - put resources in src/it/resources
// - run with "play it:test"
lazy val root = Project("root", file("."))
.configs(IntegrationTest)
.settings(Defaults.itSettings : _*)
.settings(libraryDependencies += playTest)
@hfs
hfs / build.sbt
Created March 13, 2014 11:49
sbt-native-packager: Append timestamp to version of Debian package for snapshots
version := "0.2-SNAPSHOT"
// If the version ends with "-SNAPSHOT", let the Debian version end with
// "~SNAPSHOT~yyyyMMddHHmmss". This way updates of the snapshot version can be
// detected by the package manager. Also the tilde "~" sorts before anything
// else when comparing version numbers. This way "1.0" will be regarded newer
// than "1.0~beta".
version in Debian <<= (version) { (v) =>
if (v.endsWith("-SNAPSHOT")) {
val timestampFormat = new java.text.SimpleDateFormat("yyyyMMddHHmmss");
@hfs
hfs / crcrlf.sh
Created March 21, 2014 10:51
Replace \r\r\n with \r\n in text files. \r\r\n happens typically, when an inferior VCS messes up the line endings on Windows
#!/bin/sh
find . -type f | while read each; do
if xxd -p "$each" | tr -d '\n' | grep -q 0d0d0a; then
echo "$each"
sed -i.bak -e 's/\r//' "$each"
fi
done
@hfs
hfs / putty-export.bat
Created March 31, 2014 10:30
PuTTY session configuration export/import from/into the Windows Registry
reg export HKCU\Software\SimonTatham putty.reg
@hfs
hfs / nice-wrapper.sh
Created April 10, 2014 15:00
Wrap a command with 'nice' and 'ionice' to give it lower CPU and IO priority
#!/bin/sh
#
# Start the command "$0.original", i.e. with the same name and ".original"
# appended with nice (lower CPU priority) and ionice (lower IO priority)
#
# Usage: If you want to provide "foo", rename "foo" to "foo.original", then
# link this script in "foo"'s place
nice ionice -c 3 "$0.original" "$@"
@hfs
hfs / README.md
Created April 30, 2014 18:10
Merge two files with common lines using `diff`

First file:

A
B
C
D

Second file:

C

@hfs
hfs / merge2pdf.sh
Created May 12, 2014 20:39
Merge several JPEGs into one PDF using ImageMagick
#!/bin/sh
convert input1.jpg input2.jpg input3.jpg output.pdf
@hfs
hfs / exception.oql
Created November 21, 2014 15:49
Java VisualVM query in OQL to find all the different exception messages of one exception class
unique(map(heap.objects("org.apache.avalon.framework.configuration.ConfigurationException"), "it.detailMessage.toString()"))
@hfs
hfs / backup.sh
Created January 18, 2015 14:05
Run full backup with Dirvish, mount and unmount the external backup drive, and send status output to the desktop environment as notifications
#!/bin/sh
MOUNTPOINT=/mnt/backup
notify() {
returncode=$1
summary=$2
message=$3
if [ $returncode -gt 0 ]; then