Skip to content

Instantly share code, notes, and snippets.

@RWJMurphy
RWJMurphy / cli_stub.py
Last active December 12, 2015 03:08
PEP8 compliant stub for building Python CLI tools
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ft=python ts=4 sw=4 expandtab
"""A stub for command line applications in Python."""
__version__ = "0.0.0"
import argparse
import os
reedm@www:~/tmp $ ls -ld .
drwx------ 2 reedm reedm 4096 Feb 4 14:54 ./
reedm@www:~/tmp $ cat > foo
This is a file
reedm@www:~/tmp $ chmod -w foo
reedm@www:~/tmp $ mv foo bar
reedm@www:~/tmp $ ls -la
total 12
drwx------ 2 reedm reedm 4096 Feb 4 14:54 ./
drwx-----x 54 reedm reedm 4096 Feb 4 10:18 ../
@RWJMurphy
RWJMurphy / v0.34.11.ini
Created February 10, 2013 09:09
Dwarf Therapist memory layout for DF 0.34.11 on OSX
[info]
checksum=0x8f421f9c
version_name=v0.34.11
complete=true
[addresses]
translation_vector=0x01636a88
language_vector=0x01636a70
creature_vector=0x015f56ec
dwarf_race_index=0x015dcf80
@RWJMurphy
RWJMurphy / rootkit_check.sh
Last active December 14, 2015 00:48
A basic check for the `libkeyutils` sshd rootkit.
#!/bin/bash
me=$0
die() {
echo $*
usage
exit 1
}
usage() {
@RWJMurphy
RWJMurphy / omfg_konami.js
Created March 3, 2013 22:34
The worst idea.
function wat(elem){
var color = $.Color({
hue: Math.random() * 360,
saturation: 1,
lightness: 0.5
});
$(elem).animate( { color: color }, 500, function(){wat(elem)});
}
if (window.addEventListener) {
@RWJMurphy
RWJMurphy / trac_attachment_clean.sh
Created April 5, 2013 05:57
Purges attachments from a trac instance, after a ticket has been closed for more than a given number of days.
#!/bin/bash -e
days_before_purge=30
tracdb="/var/www/trac/db/trac.db"
attachment_dir="/var/www/trac/attachments/ticket"
sqlite3="/usr/bin/sqlite3"
sql_closed="select distinct id from ticket join attachment using (id) where status = \"closed\" and datetime(changetime/1000000, 'unixepoch') <= datetime('now', '-${days_before_purge} days');"
closed_tickets=$(echo ${sql_closed} | ${sqlite3} ${tracdb})
for id in $closed_tickets; do
@RWJMurphy
RWJMurphy / proc_exe_check.sh
Last active December 16, 2015 06:38
Checks for running processes whose executable is no longer on disk. Could indicate services that have been updated and need restarting, malicious processes, etc.
#!/bin/bash
function check_proc() {
pid=$1
link=$(readlink /proc/$pid/exe)
if [[ "$link" =~ \ \(deleted\)$ ]]; then
proc_launched=$(stat -c '%y' /proc/$pid)
binary=${link% (deleted)}
binary_stat=$(stat $binary | sed 's/^/\t\t/')
cmdline=$(cat /proc/$pid/cmdline | tr '\000' ' ')
function retry() {
# retry [--limit,-l] [--delay,-d] [--] command args..
[ $# -lt 1 ] && echo "return [-ld] [--] commands [args...]" >&2 && return
LIMIT=5
DELAY=5
while [[ $# > 0 ]]; do
case $1 in
--limit|-l)
shift
@RWJMurphy
RWJMurphy / gist:7225971
Created October 30, 2013 01:45
bash scripting helpers -- command line argument parsing, and some logging functions
function usage() {
cat <<EOD
$0 [-hnv]
-h, --help Print this text and exit
-n, --dry-run Dryrun; do not make any changes
-v, --verbose Enable verbose output; repeat for more verbosity
EOD
}
function debug() {
#!/bin/bash
function silent() {
"$@" >/dev/null 2>&1
}
function command_exists() {
silent hash "$@"
}