Skip to content

Instantly share code, notes, and snippets.

@hfs
hfs / gist:2786858
Created May 25, 2012 09:11
Shell directory bookmarks
# Add this to your .bashrc, or paste it into your shell for testing
#
# Bookmarks for directories
#
# Usage:
# bm name -- Create a bookmark for the current working directory
# Bookmarks are saved across sessions in ~/.bookmarks
# to name -- cd to the bookmarked directory
# to -- Dump all bookmarks
#
@hfs
hfs / gist:3093718
Created July 11, 2012 21:31
Print a time interval given in seconds in human readable form: 2d 13h 7m 0s
human_time() {
seconds=$1
d=$(( $seconds / 86400 ))
h=$(( $seconds / 3600 % 24 ))
m=$(( $seconds / 60 % 60 ))
seconds=$(( $seconds % 60 ))
for unit in d h m; do
eval value=\$$unit
if [ $value -gt 0 ]; then
printing=true
@hfs
hfs / JIRA2TWiki.xslt
Created February 4, 2013 08:50
XSLT stylesheet to convert a JIRA bug list in XML format into a plain text table in TWiki format
<?xml version="1.0" encoding="UTF-8"?>
<!--
Stylesheet to convert a JIRA report list exported as XML into a table in
TWiki's plaintext format.
The table contains these columns:
- ID: Issue ID with link to issue page
- summary
- priority: Numerical priority – smaller number is more important
- component: one ore more, divided by </br>
@hfs
hfs / AntRegexpFileMapper.java
Created March 7, 2013 10:47
Ant regexp mapper to mass rename/move files, reading its regular expressions from a file. Public Domain code, do with it whatever you like.
package com.github.hfs.anttasks;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.CompositeMapper;
@hfs
hfs / prepend-timestamp.pl
Created March 25, 2013 16:21
Prepend the current timestamp in ISO8601 format in front of every line of output. Separator is an optional parameter, default is tab.
#!/usr/bin/perl -p
use POSIX;
BEGIN {
$| = 1;
$separator = shift or $separator = "\t";
}
print strftime("%Y-%m-%dT%H:%M:%S", localtime), $separator
@hfs
hfs / afd-git-import.sh
Created October 22, 2013 19:12
Create a git repository for the AFD [ http://www.dwd.de/AFD/ ] from a series of downloaded tarballs. Use `wget -N` to download to keep the original file timestamps, which are used as commit timestamps. This script was used to do the initial import of http://github.com/hfs/afd .
#!/bin/sh
export GIT_AUTHOR_NAME="Firstname Lastname"
export GIT_AUTHOR_EMAIL="Firstname.Lastname@example.com"
export GIT_COMMITTER_NAME="Firstname Lastname"
export GIT_COMMITTER_EMAIL="Firstname.Lastname@example.com"
mkdir afd
cd afd
git init
first=true
@hfs
hfs / sftp-cp.sh
Created November 21, 2013 12:37
Script to copy a number of files to a remote host using SFTP. Files are first copied to have a leading dot in the filename and then remotely renamed to their real name. This is useful when large files are copied, a remote process waits for them, it should not "see" unfinished files and it follows the convention to ignore files with a leading dot…
#!/bin/sh
#
# Script to copy a number of files to a remote host using SFTP. Files are first
# copied to have a leading dot in the filename and then remotely renamed to
# their real name. This script creates the input for the 'sftp' command.
#
# Usage:
# sftp-cp * | sftp user@host:/target/directory
for each in "$@"; do
@hfs
hfs / git-configure-zip-diff.sh
Created November 21, 2013 15:11
Teach git how to diff zip files by running "unzip -c" on both of them and then diffing the output
#!/bin/sh
cd $(git rev-parse --show-toplevel) || exit 128
echo "*.zip diff=zip" >> .gitattributes
git config diff.zip.textconv "unzip -c -a"
@hfs
hfs / wake-host.sh
Created November 28, 2013 08:22
Wake on LAN, then ping until the host is up
#!/bin/sh
HOST=hostname
MAC=12:34:56:78:90:AB
wakeonlan $MAC
# Wait until the host is pingable
count=0
while [ $count -lt 300 ]; do
let count++
@hfs
hfs / xml-c14n.sh
Created January 13, 2014 08:55
Canonicalize XML with xmlstarlet to make two XML files comparable
#!/bin/sh
xml c14n --without-comments $1 | xml format --dropdtd --encode utf-8 --indent-spaces 4