Skip to content

Instantly share code, notes, and snippets.

[user]
name = Tom Gidden
email = [email protected]
[alias]
unadd = reset HEAD
treelog = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d %C(bold blue)<%an>%Creset %s %Cgreen(%cr)' --abbrev-commit
cmplist = rev-list --cherry-mark --left-right --no-merges
cmplog = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d %C(bold blue)<%an>%Creset %s %Cgreen(%cr)' --abbrev-commit --cherry-mark --left-right --no-merges
cmpdiff = diff --cherry-mark --left-right --no-merges
[color]
@tomgidden
tomgidden / trimphp
Created March 20, 2013 00:04
TrimPHP: removes whitespace from EOF, EOL, and pointless ?>'s from EOF
#!/usr/bin/perl
while(<>) {
s/\s+$//s;
push @l,$_;
if(eof) {
($b=join("\n",@l))=~s/\s*(\?>)?\s*$/\n/s;
print $b;
undef @l;
}
@tomgidden
tomgidden / pebble-js-app.js
Last active December 30, 2015 07:29
Grotesque, bloated and inefficient inlining of HTML in PebbleJS app.
Pebble.addEventListener('showConfiguration', function(e) {
var o = Pebble.openURL('data:text/html;base64,PGh0bWw+PGhlYWQ+PG1ldGEgbmFtZT0idmlld3BvcnQiIGNvbnRlbnQ9IndpZHRoPTMyMCwgaW5pdGlhbC1zY2FsZT0xIj48c3R5bGU+bGFiZWwse2Rpc3BsYXk6YmxvY2t9bGFiZWx7Y2xlYXI6Ym90aDtoZWlnaHQ6NTBweH1pbnB1dHtmbG9hdDpyaWdodH08L3N0eWxlPjwvaGVhZD48Ym9keT48aDE+UGViYmxlSlMgYmxvYXRlZCBpbmxpbmUgSFRNTDwvaDE+PGZvcm0gaWQ9ImYiIG9uc3VibWl0PSJyZXR1cm4gcyh0aGlzKSI+PGxhYmVsPkZvbzxpbnB1dCB0eXBlPSJjaGVja2JveCIgbmFtZT0iZm9vIj48L2xhYmVsPjxsYWJlbD5CYXI8aW5wdXQgdHlwZT0iY2hlY2tib3giIG5hbWU9ImJhciI+PC9sYWJlbD48bGFiZWw+U2F2ZTxpbnB1dCB0eXBlPSJzdWJtaXQiPjwvbGFiZWw+PC9mb3JtPjxzY3JpcHQ+ZnVuY3Rpb24gcyhlKXtmb3Iobz17fSxpPTA7aTxlLmxlbmd0aDtpKyspKGo9ZVtpXS5uYW1lKSYmKG9bal09ZVtpXS5jaGVja2VkPzE6MCk7cmV0dXJuIHdpbmRvdy5sb2NhdGlvbi5ocmVmPSJwZWJibGVqczovL2Nsb3NlIyIrSlNPTi5zdHJpbmdpZnkobyksITF9PC9zY3JpcHQ+PC9ib2R5PjwvaHRtbD4K');
}
@tomgidden
tomgidden / client.pl
Created January 22, 2014 13:27
Gruesome hack to get a Windows box to print a file
sendToPC(host_win('windows_host'), "print", 'url_of_thing_to_print');
my %wincache;
sub host_win
{
my $hostname = shift;
return $wincache{$hostname}[0]
if($wincache{$hostname}[1] and (time() - $wincache{$hostname}[1]) < $wincache_timeout);
my $result = `nmblookup $hostname`;
@tomgidden
tomgidden / mkdirp.js
Last active August 29, 2015 13:56
node.js mkdirp
var fs = require('fs');
function mkdirp(fn, perms, cb)
// Make a directory and its ancestors if necessary.
{
// 'perms' is optional, but callback is the last param
if(arguments.length === 2) {
cb = arguments[arguments.length-1];
perms = 0x1fd/*0775*/;
}
@tomgidden
tomgidden / ziplogs.zsh
Created January 7, 2015 11:16
zsh-based log compilation and zipping
#!/usr/bin/env zsh
LOGDIR=`pwd`/../log
# Log files start with...
LOGPREFIX=$LOGDIR/test
# Logs for days where at least part of the day is more than $ZIPAFTER hours ago will be zipped.
# Note the subtlety: if this is set to 24, then _all_ of yesterday will be zipped, not just the
# hours up until 24 hours before the current time.
@tomgidden
tomgidden / geek_number_format.php
Created January 7, 2015 11:50
1024 => 1M, 1048576 => 1G, etc.
<?php
function geek_number_format($val, $withSpace=true, $suffix='')
{
$val = intval($val);
$units = array('', 'k', 'M', 'G', 'T', 'P', 'E');
while ($units and $val >= 1024) {
$val >>= 10;
array_shift($units);
}
@tomgidden
tomgidden / approx_duration.php
Created January 7, 2015 11:52
Converts a duration (in seconds) to human readable. A bit crunky, and doesn't work that well.
<?php
function approx_duration($duration, // time period in question, in seconds
$short=false, // single letter suffices (m=month and minute!)
$roundupdown=true, // round up/down rather than just down
$keepdays=false, // largest division is days, not years/months/weeks/days
$keepzeros=true, // keep (and count) zero values
$cutoff=2, // maximum number of fields
$blankzeros=true) // even if $keepzeros for cutoff, eliminate from display
{
@tomgidden
tomgidden / filter_plugins__match_ip.py
Created February 2, 2015 17:42
Ansible: get IP address of host by regular-expression
# file: filter_plugins/match_ip.py
from ansible import errors
import re
def match_ip(ips, pattern):
if type(ips) != list:
raise errors.AnsibleFilterError("|failed expects a list")
for ip in ips:
@tomgidden
tomgidden / pke_common.php
Last active August 29, 2015 14:15
Storing sensitive data in PHP using PKE
<?php
# First, create a key pair:
# openssl genrsa -aes256 2048 > private.pem
# openssl rsa -in private.pem -pubout > public.pem
define('SALT', 'Confidential (but not really critically secret) string that should not change. Just to stop rainbow tabling.');
define('PRIVATE_KEY_FILE', './private.pem');
define('PUBLIC_KEY_FILE', './public.pem');
define('DATA_DIR', '.');