Skip to content

Instantly share code, notes, and snippets.

import boto3
from base64 import b64decode
import json
from urllib2 import urlopen, Request
ENCRYPTED_GITHUB_TOKEN = (
# aws kms encrypt --profile <PROFILE_NAME> --region <REGION>
# --key-id <KMS_KEY_ID> --plaintext <GITHUB_ACCESS_TOKEN>
# --query CiphertextBlob --output text
)
@nicwolff
nicwolff / .bashrc
Created February 9, 2016 22:29
Pass password and command to PSSH sudo
( echo "PASSWORD" ; echo "COMMAND" ) | pssh -t 1 -h ~/host_list -P -I "sudo -S su -"
@nicwolff
nicwolff / dotdict.py
Created October 26, 2015 21:56
Python dict subclass that can be indexed with object.attribute syntax
class dotdict(dict):
def __getattr__(self, attr):
return self[attr]
def __missing__(self, key):
self[key] = dotdict()
return self[key]
__setattr__ = dict.__setitem__
@nicwolff
nicwolff / .bash_profile
Created March 6, 2015 20:21
Send VT100 "Report Device OK" every 60 seconds to keep SSH from timing out
# Send VT100 "Report Device OK" every 60 seconds to keep SSH from timing out
notidle() { printf "\033[0n"; sleep 60; notidle; }
PARENT_CMD=$(/bin/ps -ocommand= -p $PPID)
if [ ${PARENT_CMD:0:5} = "sshd:" ]; then
{ notidle 2>&3 & } 3>&2 2>/dev/null
fi
@nicwolff
nicwolff / gist:04c270c70bde89ee3815
Created February 13, 2015 17:51
Compile little precise-time program
cat | cc -xc -o time -
#include <stdio.h>
#include <sys/time.h>
int main(void)
{
struct timeval time_now;
gettimeofday(&time_now,NULL);
printf ("%ld secs, %d usecs\n",time_now.tv_sec,time_now.tv_usec);
return 0;
@nicwolff
nicwolff / XML_breaker.py
Last active July 21, 2025 21:07
Python script to break large XML files
import os
import sys
from xml.sax import parse
from xml.sax.saxutils import XMLGenerator
class CycleFile(object):
def __init__(self, filename):
self.basename, self.ext = os.path.splitext(filename)
self.index = 0
@nicwolff
nicwolff / gist:33870d023ce91b82a048
Last active August 29, 2015 14:08
Atomic non-blocking advisory lock on NFS using hard links
sub do_something {
my $path = shift;
# Skip this if another server is already working on it
return unless my $lock = LinkLock->lock($path);
my $users = Get_arrayref_from_database();
open my $fh, '>', $path;
print $fh join( ':', @$_ ), "\n" for @$users;
@nicwolff
nicwolff / vector.js
Created October 21, 2014 15:27
https://en.wikipedia.org/wiki/Special:MyPage/vector.js to go directly to Google Maps from lat/long links
var gmaps = "//www.google.com/maps/preview#!q=";
function coordsToGmaps(){
var anchors = document.getElementsByClassName('external');
var i = anchors.length;
while ( i-- ) {
var a = anchors[i];
if ( a.href.match( /geohack/ ) ) {
var geodec = a.querySelectorAll('.geo-dec');
var latlong = geodec[0].textContent;
@nicwolff
nicwolff / .bash_profile
Last active August 29, 2015 14:01
Bash configuration
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
bind '"\e[A":history-search-backward'
@nicwolff
nicwolff / sum-mason-trace.pl
Last active August 29, 2015 13:57
Filter to show time spent in subcomponents in Mason profile log
#!/usr/bin/perl -nl
next unless ($p) = /(\d+)-\d+$/;
s/\\n.*//;
s/.*\ - //;
s/{{{/{/ and $t{$p}{++$d{$p}} = 0;
s/}}}/}/ and --$d{$p} and /(\d+\.\d+)/ and $t{$p}{$d{$p}} += $1 and $a = $t{$p}{$d{$p}+1} and $r = round($1-$a) and s{$}{ / $r};
print;
sub round { int($_[0]*10000+.5)/10000 }