Skip to content

Instantly share code, notes, and snippets.

@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 / compress-pdf.sh
Created July 7, 2014 09:32
Compress a PDF file of scanned JPEGs using ImageMagick. Source: http://superuser.com/questions/427851/batch-resize-and-compress-pdf-files
convert -density 200 -compress jpeg -quality 20 input.pdf output.pdf
@hfs
hfs / dbus_nm_ssid.py
Created July 26, 2014 20:28
Query NetworkManager via DBUS in Python: Get the SSID of the active wireless connection
#!/usr/bin/env python
import dbus
NM = 'org.freedesktop.NetworkManager'
NMCA = NM + '.Connection.Active'
NMDW = NM + '.Device.Wireless'
NMAP = NM + '.AccessPoint'
DBUS_PROPS = 'org.freedesktop.DBus.Properties'
@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
@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 / 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}'
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();
#!/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 "$@"
@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 "$@"