Skip to content

Instantly share code, notes, and snippets.

View empiricalthought's full-sized avatar
🎵

Steven Huwig empiricalthought

🎵
View GitHub Profile
#!/usr/bin/env awk -f
NR > 1 {
for (i = 1; i <= header_count; i++) {
print headers[i], $i
}
}
NR == 1 {
header_count = split($0, headers)
@empiricalthought
empiricalthought / sample.py
Created December 21, 2017 21:29
openpyxl named range
from openpyxl import load_workbook
workbook = load_workbook(filename='./tmp/book.xlsx', read_only=True)
range = workbook.defined_names['a_named_range']
for sheet_title, sheet_coords in range.destinations:
sheet = workbook[sheet_title]
for row in sheet[sheet_coords]:
print "\t".join(str(cell.value) for cell in row)
PS1=[\d/\t] \h:\W \u$
@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} \
@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 / 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 / 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 / .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 / 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 / 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