Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / decrypt.sh
Last active May 20, 2019 02:03
Easily encrypt/decrypt and secure delete plaintext files using GPG (GNU Privacy Guard / OpenPGP) on OS X
#!/bin/bash
if test -z "$1"
then
echo "usage: decrypt <filename>"
else
gpg -q --decrypt $1
fi
@stantonk
stantonk / hg_batch_pull.sh
Created March 7, 2012 17:05
Perform batch "pull -u" on multiple Mercurial repositories from the parent directory
#!/bin/bash
# This script finds all the mercurial repositories in the current directory
# and does a "hg pull -u" to get the latest changes from all the repositories.
#
# Make sure you know what you're doing before running this ;-)
confirm_prompt() {
read -p "Are you sure you want to 'hg pull -u' every repository? " -n 1
echo
@stantonk
stantonk / hgbatch.sh
Created March 8, 2012 17:06
Batch execute any single mercurial command on all repositories within a directory.
#!/bin/bash
# This script finds all the mercurial repositories in the current directory
# and does a "hg $@" to batch execute a mercurial command in all the repositories.
#
# Make sure you know what you're doing before running this ;-)
#
# Examples:
#
# Perform pull -u on all repositories to get the latest changes and update:
@stantonk
stantonk / .gvimrc.after
Created March 27, 2012 22:25
My current .gvimrc.after
"colo dawn
"colo ir_black
"colo maroloccio
colo darkbone
"set guifont=Monaco:h14
set guifont=DejaVu\ Sans\ Mono\ Bold:h14
"set guifont=Inconsolata\ Bold:h16
set hls is ic scs
set gcr=n:blinkon0
@stantonk
stantonk / date2epoch.py
Last active October 5, 2015 15:47
date2epoch
#!/usr/bin/env python
# Notes
# One can easily get the current epoch using the date command, like so:
#
# in your timezone:
#
# $ date -j +"%s"
# 1363104249
#
@stantonk
stantonk / csv
Last active October 5, 2015 22:07
Read a list of values separated by newlines from stdin and output the values on a single line separated by commas to stdout
#!/usr/bin/env bash
######
# Why is this useful?
#
# Say you have a list of ids in a database tool like SequelPro in
# the result of a query. It is possible to copy an entire column
# to the clipboard. But then you may want to pass that list of
# ids as a comma-separated list into an HTTP(S) API endpoint for
# testing. This solves that problem!
@stantonk
stantonk / doit
Created November 15, 2012 22:46
Install python 2.7.3 on CentOS 5.8
#!/bin/bash
# Source: http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/
yum groupinstall "Development tools"
yum install zlib-devel
yum install bzip2-devel openssl-devel ncurses-devel
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar xf Python-2.7.3.tar.bz2
cd Python-2.7.3
@stantonk
stantonk / flake8.xml
Created January 26, 2013 01:17
PyCharm Flake8 Configuration XML File
<!-- Drop this in ~/Library/Preferences/PyCharm20/tools -->
<!-- make sure you set the path to flake8 executable for your machine in the COMMAND option -->
<?xml version="1.0" encoding="UTF-8"?>
<toolSet name="Flake8">
<tool name="Flake8 File" showInMainMenu="true" showInEditor="true" showInProject="true" showInSearchPopup="false" disabled="false" useConsole="true" synchronizeAfterRun="true">
<exec>
<option name="COMMAND" value="/usr/local/share/python/flake8" />
<option name="PARAMETERS" value="--max-line-length=120 --ignore=E301,E302,E261,E262,W404 $FileDir$/$FileName$" />
<option name="WORKING_DIRECTORY" value="$FileDir$" />
@stantonk
stantonk / unicode_examples.py
Created February 6, 2013 20:20
Shows how unicode & str types, utf-8 and ascii encodings interoperate with each other in Python 2.x
import sys
def _helper(s, method, encoding):
try:
print 'print s.%s(\'%s\'): %s' % (method, encoding, getattr(s, method)(encoding))
except UnicodeError as e:
print 'print s.%s(\'%s\'): %s' % (method, encoding, e)
def test_encodings(s):
@stantonk
stantonk / multitail.sh
Created February 27, 2013 21:43
Unified tail -f of a log file across multiple hosts via ssh.
#!/bin/bash
HOSTS=(PUT, YOUR, HOSTS, HERE)
CMD="tail -f logs/api.log"
echo "Hit CTRL-C to stop"
sleep 0.5
PIDS=""
for host in ${HOSTS[*]}
do