Skip to content

Instantly share code, notes, and snippets.

@kckrinke
kckrinke / clean-tmp-files.sh
Created November 1, 2016 22:52
Recursively find and remove temporary files (#*# and *~)
#!/bin/bash
function display_usage () {
while [ $# -gt 0 ]
do
echo "Error: $1"
shift
done
echo "usage: $(basename $0) <path> [paths]"
exit 1
@kckrinke
kckrinke / emacs-src-files.sh
Created November 1, 2016 22:55
Recursively find all "source" files, based on extension, and edit them with emacs.
#!/bin/bash
SCRIPT_NAME=$(basename "$0")
EMACS_BIN=$(echo "${SCRIPT_NAME}" | perl -pe 's!^([-_\w]+?)\-src-files$!$1!;')
DEFAULT_FILE_TYPES=c,h,cpp,hh,cs,ac,am,java,js,pl,py,pm,sh,xml,php,css,lisp,rst,go
SET_FILE_TYPES=
ADD_FILE_TYPES=
DEL_FILE_TYPES=
TARGET_PATHS=
@kckrinke
kckrinke / o.sh
Created November 1, 2016 22:58
Wrapper around xdg-open except if the given item is a directory - use caja instead.
#!/bin/bash
if [ $# -eq 0 \
-o "$1" == "-h" \
-o "$1" == "--help" \
]
then
echo "usage: $(basename $0) [-h|--help] URI [URI [...]]"
exit 1
fi
@kckrinke
kckrinke / tor-arm
Created November 1, 2016 22:59
User wrapper script for running 'arm' as debian-tor rather than the actual user.
#!/bin/bash
[ "$USER" == "debian-tor" ] || /usr/bin/sudo -u "debian-tor" "$0" "$@"
exec /usr/bin/arm "$@"
@kckrinke
kckrinke / uri_unescape.pl
Created November 1, 2016 23:02
Un-escape the given URI-encoded text.
#!/usr/bin/env perl
use strict;
use warnings;
use URI::Escape;
unless (@ARGV && ! grep {m/^(\-h|\-\-help)$/} @ARGV) {
print "usage: uri_unescape <uri-encoded-string>\n";
print "usage: cat file | uri_unescape -\n";
exit 1;
}
@kckrinke
kckrinke / reverse-taxes.pl
Created November 1, 2016 23:06
Given the tax percentage (as an INT) and the actual total - calculate what the pre-tax value would be in order to arrive at the given total. ie: $86.95 + 15% = $100.00 with the 86.95 being the number this script figures out.
#!/usr/bin/env perl
use strict;
use warnings;
unless (@ARGV >= 2) {
print "usage: reverse-taxes <tax> <total>\n";
exit 1;
}
@kckrinke
kckrinke / readlink.pl
Created November 5, 2016 23:10
Wrapper to fix "-/..." arguments passed to readlink. Some scripts, beyond control, are calling readlink on "-/bin/bash" for example. This is obviously a problem because of the leading "-". Rename /bin/readlink to /bin/readlink.real and use this script as /bin/readlink to correct the issues.
#!/usr/bin/env python
import os, sys, time
#
# == Summary ==
# Proving that the following statement is best practice for determining if
# this python program is being run from a terminal or if it is daemonized.
#
@kckrinke
kckrinke / truncate-long-lines.sh
Created November 9, 2016 20:21
Truncate lines from STDIN to an arbitrary length on it's way to STDOUT
#!/bin/bash
: "${LENGTH:=79}"
usage() {
while [ $# -gt 0 ]; do echo "$1"; shift; done
echo "usage: $(basename $0) [options]"
echo "options:"
echo " -h This usage information screen"
echo " -l Truncate to given length (default: 79)"
@kckrinke
kckrinke / find-src.sh
Last active November 9, 2016 21:07
Conveniently find source code files (based on file extensions).
#!/bin/bash
usage() {
while [ $# -gt 0 ]; do echo "$1"; shift; done
echo "usage: $(basename $0) [options] [path ...]"
echo "options:"
echo " -h This usage information screen"
echo " -n Dry run, just print command"
echo " -t Explicit source file extn"
echo