Skip to content

Instantly share code, notes, and snippets.

View vizowl's full-sized avatar

Chris Knox vizowl

  • Wellington, New Zealand
  • X @vizowl
View GitHub Profile
@vizowl
vizowl / load-csv.py
Created April 15, 2013 09:41
Pythonic way to import variable column length csv data into postgresql
import psycopg2 as dbapi
import csv
from itertools import izip, count
if __name__ == "__main__":
con = dbapi.connect(database='play')
cur = con.cursor()
data = ([str(212), str(i)] + row + (15 - len(row)) * [','] for row, i in izip(csv.reader(open('test.csv')), count()))
sql = open('test.sql').read()
@vizowl
vizowl / histogram.py
Last active August 29, 2015 14:16
Image histogram
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
img=mpimg.imread('image.jpg')
lum_img = img[:,:,0]
p = plt.hist(lum_img.flatten(), 256, range=(0.0,255), fc='k', ec='k')
plt.savefig('out.png')
@vizowl
vizowl / histogram.py
Last active August 29, 2015 14:16
Histogram 2
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import numpy as np
img=mpimg.imread('image.jpg')
lum_img = img[:,:,0]
p = plt.hist(lum_img.flatten(), 256, range=(0.0,255), fc='k', ec='k')
plt.savefig('/output/out.png')
@vizowl
vizowl / makefile
Last active August 29, 2015 14:16
Makefile for creating a histogram in a docker container
NAME := $(shell uuidgen -r)
out.png: histogram.py image.jpg
docker run --name $(NAME) -w /work -v $$PWD:/work -v /output \
ipython/scipystack python histogram.py
docker cp $(NAME):/output/out.png .
docker rm $(NAME)
@vizowl
vizowl / makefile
Last active August 29, 2015 14:16
Makefiles for both inside and outside docker
NAME := $(shell uuidgen -r)
out.png: run/*
docker run --name $(NAME) -w /work -v $$PWD:/work -v /output \
ipython/scipystack python make $(MFLAGS)
docker cp $(NAME):/output/out.png .
docker rm $(NAME)
@vizowl
vizowl / makefile
Created February 26, 2015 22:53
Another makefile for docker
NAME := $(shell uuidgen -r)
.PHONY: all
all: run/*
docker run --name $(NAME) -w /work -v $$PWD:/work -v /output \
ipython/scipystack python make $(MFLAGS)
docker cp $(NAME):/output/out.png .
docker rm $(NAME)
@vizowl
vizowl / makefile
Last active August 29, 2015 14:16
Volume based makefile for docker control
all: run/* .datavol
docker run --rm --volumes-from=$$(cat .datavol) -w /work -v $$PWD/run:/work \
-v /output ipython/scipystack make $(MFLAGS)
docker cp $$(cat .datavol):/output/out.png .
.datavol:
docker run --cidfile=$@ -v /output debian
clean:
docker rm -f $$(cat .datavol)
@vizowl
vizowl / makefile
Created February 27, 2015 01:45
Volume based makefile for docker containers with dependency management
DATAVOL := docker-tutorial-data-container
all: out.png
out.png: run/* .datavol
docker run --rm --volumes-from=$(DATAVOL) -w /work -v $$PWD/run:/work \
-v /output ipython/scipystack make $(MFLAGS)
docker cp $(DATAVOL):/output/out.png .
.datavol:
docker run --name $(DATAVOL) -v /output debian
@vizowl
vizowl / makefile
Last active August 29, 2015 14:16
Makefiles that use container restarting to persist intermediates and targets
CID := .container
CONTAINER = $(shell cat $(CID) 2>/dev/null)
all: out.png
out.png: run/*
ifneq "$(CONTAINER)" ""
docker restart $(CONTAINER)
docker attach $(CONTAINER) || docker logs $(CONTAINER)
else
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory