Skip to content

Instantly share code, notes, and snippets.

View empiricalthought's full-sized avatar
🎵

Steven Huwig empiricalthought

🎵
View GitHub Profile
@empiricalthought
empiricalthought / gist:2712855
Created May 16, 2012 18:33
PL/Python exception bug
create function python_exception_bug()
returns void as $$
raise plpy.spiexceptions.InvalidParameterValue()
$$ language 'plpython3u';
create function python_exception_sql()
returns text as $$
begin
select python_exception_bug();
return 'cannot happen';
(defun huwigs-build-ipregistry (clean)
"Build the IP Registry UI project.
Argument CLEAN if prefix arg is given, clean and then build."
(interactive "P")
(let ((default-directory *ipregistry-project-directory*)
(command (if clean
"/home/huwigs/bin/mvn -B clean pmd:check tomcat6:run"
"/home/huwigs/bin/mvn -DskipTests=true tomcat6:run"))
(tags-revert-without-query t))
@empiricalthought
empiricalthought / spinner.py
Created July 30, 2012 19:11
Python 3 ASCII spinner for progress feedback
import itertools
import sys
def spinner(granularity):
"""Wraps a function in an ASCII spinner display loop. granularity
represents the number of times the function should be called
before moving the spinner."""
spinner_chars = itertools.cycle("\|/-")
def make_spinner(f):
calls = 0
@empiricalthought
empiricalthought / generate_insert_statements.awk
Created August 21, 2012 15:09
Awk script to generate SQL inserts from tab file
#!/usr/bin/gawk -f
BEGIN {
if (!table) {
print "usage: generate_insert_statements.awk -v table=TARGET_TABLE_NAME [datafiles ...]" > "/dev/stderr"
failed = 1
exit 1
}
FS = FS ? FS : "\t"
freq = freq ? freq : 100
@empiricalthought
empiricalthought / aquaman.sh
Created August 25, 2012 03:08
Simple shell script to open a typeset manpage on OS X
#!/bin/bash
man -t $@ | open -a /Applications/Preview.app -f
@empiricalthought
empiricalthought / .ctags
Created March 4, 2013 21:47
Exuberant CTags configuration for CoffeeScript and Python
--langdef=coffee
--langmap=coffee:+.coffee
--regex-coffee=/(^|=[ \t])*class ([A-Za-z.]+)( extends [A-Za-z.]+)?$/\2/c,class/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?@?([A-Za-z.]+):.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*(module\.)?(exports\.)?([A-Za-z.]+)[ \t]+=.*[-=]>.*$/\3/f,function/
--regex-coffee=/^[ \t]*([A-Za-z.]+)[ \t]+=[^->\n]*$/\1/v,variable/
--languages=coffee,python
@empiricalthought
empiricalthought / bug.rest
Created March 11, 2013 20:43
I think this is a github bug.
  1. Item 1. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

  2. Item the second. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

  3. A third item.

    New Paragraph under 3.

  4. The fourth one. Lorem ipsum dolor sit amet

@empiricalthought
empiricalthought / CheckGitHubPR.scpt
Created December 14, 2013 21:48
This Applescript can be applied as a rule to incoming GitHub pull request notification e-mails. It will create a reminder in the OS X "Reminders" app if the assignee matches the account on the incoming mail.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set credentials to do shell script "security find-internet-password -g -s github.com 2>&1 | awk '
/^password:/ {
sub(\".*password: \\\"\", \"\")
sub(\"\\\".*\", \"\")
password = $0
}
/acct/ {
@empiricalthought
empiricalthought / gist:d78a1584b92e1e144354
Created October 13, 2014 00:26
Postgresql streaming replication output
2014-10-13 00:14:57 UTC LOG: database system was interrupted; last known up at 2014-10-13 00:14:52 UTC
2014-10-13 00:14:57 UTC LOG: creating missing WAL directory "pg_xlog/archive_status"
2014-10-13 00:14:57 UTC LOG: entering standby mode
2014-10-13 00:14:57 UTC LOG: restored log file "000000010000000000000002" from archive
2014-10-13 00:14:57 UTC LOG: redo starts at 0/2000028
2014-10-13 00:14:57 UTC LOG: consistent recovery state reached at 0/20000F0
2014-10-13 00:14:57 UTC LOG: database system is ready to accept read only connections
cp: cannot stat ‘/data/wal_archive/000000010000000000000003’: No such file or directory
2014-10-13 00:14:57 UTC LOG: started streaming WAL from primary at 0/3000000 on timeline 1
2014-10-13 00:14:57 UTC LOG: incomplete startup packet
@empiricalthought
empiricalthought / mfa_wrap.sh
Created June 7, 2017 16:22
Bash function to automate MFA for interactive awscli usage
# To use this wrapper,
# $ . ./mfa_wrap.sh
# $ mfa_wrap 123456 'aws s3 ls'
mfa_wrap() {
MFA_TOKEN="$1"
shift
SHELL_CMD=$(aws sts get-session-token \
--serial-number="${AWS_MFA_SERIAL?AWS_MFA_SERIAL must be set}" \
--token-code=${MFA_TOKEN} \