Skip to content

Instantly share code, notes, and snippets.

@hfs
hfs / TiffSet.java
Created March 6, 2017 08:28
Command line tool to set TIFF header fields using JAI
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.sun.media.jai.codec.TIFFField;
public class TiffSet {
public static void main(String[] args) {
@hfs
hfs / readableSize.java
Created February 7, 2017 09:34
Convert a byte count into a human readable, rounded String using kB, MB, etc. This is base-1000 and not base-1024.
/**
* Convert a byte count into a human readable, rounded String using kB, MB,
* etc. This is base-1000 and not base-1024.
*
* @param size number of bytes
* @return formatted String
*/
private static String readableSize(long size) {
if (size <= 0) {
return "0 B";
@hfs
hfs / git2debchangelog.sh
Created October 12, 2016 09:53
Convert git log into changelog in Debian format
#!/bin/bash
#
# Convert git log into changelog in Debian format
#
# Tags in format 1.2.3-4 become version entries. Log entries between them
# become changelog entries. Merge commits are not excluded, so you probably
# have to clean up the result manually.
RE_VERSION='^v\?[0-9]\+\([.-][0-9]\+\)*'
# Assume the name of the current directory is the package name
@hfs
hfs / hexdump.sh
Created May 3, 2016 14:11
Poor man’s hexdump using “od” if “xxd“ or “hexdump” is not available
#!/bin/sh
od -c -t x1 "$@"
#!/bin/sh
echo 0 | gdb -batch-silent -ex "run" -ex "set logging overwrite on" -ex "set logging file gdb.bt" -ex "set logging on" -ex "set pagination off" -ex "handle SIG33 pass nostop noprint" -ex "echo backtrace:\n" -ex "backtrace full" -ex "echo \n\nregisters:\n" -ex "info registers" -ex "echo \n\ncurrent instructions:\n" -ex "x/16i \$pc" -ex "echo \n\nthreads backtrace:\n" -ex "thread apply all backtrace" -ex "set logging off" -ex "quit" --args "$@"
import hudson.util.RemotingDiagnostics;
script = 'def proc = "ls -1 /media".execute(); proc.waitFor(); println proc.in.text';
for (slave in Jenkins.instance.slaves) {
println slave.name;
try {
println RemotingDiagnostics.executeGroovy(script, slave.getChannel());
} catch (all) {
all.printStackTrace();
@hfs
hfs / du-files.sh
Created October 6, 2015 07:43
Sum of sizes of files in a directory structure without counting directory sizes
#!/bin/sh
find -type f -printf '%s\n' | awk '{s+=$1} END {print s}'
@hfs
hfs / nasaBackground.sh
Last active October 9, 2015 18:51
Awesome window manager: Fetch the NASA Image of the Day and set it as background
#!/bin/bash -e
# Grabs the NASA image of the day by RSS feed and updates the gnome
# background. add this to your cron jobs to have this happen daily. this is,
# obviously, a hack, that is likely to break at the slightest change of NASA's
# RSS implementation. yay standards!
#
# Source: https://awesome.naquadah.org/wiki/NASA_IOTD_Wallpaper
FEED='http://www.nasa.gov/rss/lg_image_of_the_day.rss'
@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
@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()"))