Skip to content

Instantly share code, notes, and snippets.

@shazow
shazow / _thumbnail.py
Last active August 29, 2015 13:57
Thumbnailing helpers.
from math import ceil
def resize_dimensions(x, y, max_width=None, max_height=None, min_side=None, max_side=None):
if not any([max_width, max_height, min_side, max_side]):
return x, y
original_x, original_y = x, y
priority_width = True
if max_width and x > max_width:

Keybase proof

I hereby claim:

  • I am shazow on github.
  • I am shazow (https://keybase.io/shazow) on keybase.
  • I have a public key whose fingerprint is 9FCE A980 CCFD 3C13 E11E 88A9 3506 87D1 7E81 FD68

To claim this, I am signing this object:

@shazow
shazow / nightmare.py
Created April 24, 2014 22:21
A "higher-level" socket module for Python. Inspired by the lovely urllib2.
s = socket2.build_opener(socket2.IPv4Resolver(host), port);
s.addsecurewrap = socket.wrap_socket
conn = s.open()
@shazow
shazow / gist:11339093
Last active August 29, 2015 14:00 — forked from dahu/gist:11338846
autocmd CursorMoved,CursorMovedI * hi FOW ctermfg=black ctermbg=NONE guifg=#444444 guibg=NONE
call matchadd('FOW', '\%(.*\n\)\{1,20\}\ze\%(.*\n\)\{3\}.*\%#')
call matchadd('FOW', '.*\%#.*\%(\n.*\)\{3\}\zs\%(.*\n\)\{1,20\}')
@shazow
shazow / metaclass_woes.py
Created June 18, 2014 04:38
Python Metaclass woes.
storage = {}
class RegistryMeta(type):
def __init__(cls, name, bases, attrs):
super(RegistryMeta, cls).__init__(name, bases, attrs)
id = getattr(cls, 'id', None)
if not id:
return
@shazow
shazow / Dockerfile
Created July 3, 2014 20:30
PostgreSQL Dockerfile
# DOCKER-VERSION 0.6.1
# Borrowed from https://github.com/vvlad/dockerfiles-postgresql-9.3
#
# First run:
# $ docker build -t postgresql -rm=true .
# $ ID=$(docker run -e "CREATE_DB=foo" -v "path/to/socks:/var/run/postgresql" -d postgresql)
# $ docker wait $ID
# $ docker logs $ID
FROM ubuntu:12.04
@shazow
shazow / Dockerfile
Created July 3, 2014 20:38
UWSGI Docker
# DOCKER-VERSION 0.6.1
# Borrowed from https://github.com/vvlad/dockerfiles-postgresql-9.3
#
# First run:
# $ docker build -t uwsgi -rm=true .
# $ ID=$(docker run -v "path/to/src:/app/src" -v "path/to/socks:/app/socks" -d uwsgi)
# $ docker wait $ID
# $ docker logs $ID
FROM ubuntu:12.04
#!/bin/sh
NAME="$(basename $0)"
ARCH="$(uname -sm)"
tail -n +6 $0 | tar -s "/$ARCH/$NAME/" -zx "$ARCH"
exec $0 $@
exit
(... tarball ...)
@shazow
shazow / gist:6dd544b9b17e69f4cd77
Last active August 29, 2015 14:16
Go pattern? Search buffered chan
// This is getting out of hand, probably a bad idea.
func (c *Client) searchBuffer(command string) (message *irc.Message, err error) {
buffer := make(chan *irc.Message, cap(c.buffer))
Fill:
for {
select {
case message = <-c.buffer:
if message.Command == command {
@shazow
shazow / learning-opengl.md
Last active August 14, 2018 18:36
Notes on learning OpenGL