Skip to content

Instantly share code, notes, and snippets.

Avatar

Gil Raphaelli graphaelli

View GitHub Profile
@graphaelli
graphaelli / test_pg_conn_mock.py
Created Dec 9, 2016
test pg connection mock
View test_pg_conn_mock.py
#!/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 Apr 19, 2017
batch postgresql updates with a CTE
View batch-update.sql
-- 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 Apr 26, 2017
quote a list of inputs, mostly for use in sql queries
View quote_list.py
#!/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 Apr 27, 2017
rebase all branches with branch
View git-rebase-all.py
#!/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
firefox in ubuntu 16.04 docker container on mac osx
View Dockerfile
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
View awacs_list_actions.py
#!/usr/bin/env python
import importlib
import sys
def actions(module):
mod = importlib.import_module(module)
for attrib in dir(mod):
View nocachehttpserver.go
package main
import (
"log"
"net/http"
"time"
)
// https://raw.githubusercontent.com/zenazn/goji/master/web/middleware/nocache.go
View gotestwatch.sh
#!/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 Dec 29, 2017
Export environment variables for AWS cli w/MFA.
View aws-session-env.py
#!/usr/bin/env python
"""Export environment variables for AWS cli w/MFA.
eval $(aws-session-env.py $1)
"""
import argparse
import os
import boto3
View go-path-rebuild.sh
#!/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 \