Skip to content

Instantly share code, notes, and snippets.

View graphaelli's full-sized avatar

Gil Raphaelli graphaelli

View GitHub Profile
@graphaelli
graphaelli / test_pg_conn_mock.py
Created December 9, 2016 03:55
test pg connection mock
#!/usr/bin/env python
from __future__ import print_function
try:
import mock
except ImportError:
from unittest import mock
import unittest
@graphaelli
graphaelli / batch-update.sql
Created April 19, 2017 22:44
batch postgresql updates with a CTE
-- based on https://news.ycombinator.com/item?id=9018756
=# select *, 'foo'::text into test from generate_series(1,5) as id;
SELECT 5
Time: 77.975 ms
=# select * from test;
┌────┬──────┐
│ id │ text │
├────┼──────┤
│ 1 │ foo │
│ 2 │ foo │
@graphaelli
graphaelli / quote_list.py
Created April 26, 2017 16:42
quote a list of inputs, mostly for use in sql queries
#!/usr/bin/env python
from io import StringIO
import argparse
import sys
import unittest
def quote_list(r, sep=None):
# hope r is smallish
@graphaelli
graphaelli / git-rebase-all.py
Last active April 27, 2017 17:25
rebase all branches with branch
#!/usr/bin/env python
import argparse
import os
import subprocess
import sys
def rebase(base, branch, abort=True):
try:
@graphaelli
graphaelli / Dockerfile
Last active May 14, 2017 04:25
firefox in ubuntu 16.04 docker container on mac osx
FROM ubuntu:16.04
# based on http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/
RUN apt-get update && apt-get install -y firefox
RUN useradd -u 501 -m developer
USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox
#!/usr/bin/env python
import importlib
import sys
def actions(module):
mod = importlib.import_module(module)
for attrib in dir(mod):
package main
import (
"log"
"net/http"
"time"
)
// https://raw.githubusercontent.com/zenazn/goji/master/web/middleware/nocache.go
#!/bin/bash
gotest() {
clear
go test -bench .
}
gotest
export -f gotest
fswatch -o *go | xargs -t -I{} bash -c gotest
@graphaelli
graphaelli / aws-session-env.py
Created December 29, 2017 18:21
Export environment variables for AWS cli w/MFA.
#!/usr/bin/env python
"""Export environment variables for AWS cli w/MFA.
eval $(aws-session-env.py $1)
"""
import argparse
import os
import boto3
#!/bin/bash -e
if [ ! -d ${GOPATH} ]; then
echo missing GOPATH
exit 1
fi
mv ${GOPATH} ${GOPATH}.$(date '+%Y%m%d_%H%M%S')
mkdir -p ${GOPATH}
go get -u -v \