Skip to content

Instantly share code, notes, and snippets.

View mechanical-snail's full-sized avatar

Mechanical snail mechanical-snail

View GitHub Profile
@mechanical-snail
mechanical-snail / iterable_to_stream.py
Created November 28, 2013 07:19
Use an iterable of bytestrings as a read-only input stream
#!/usr/bin/python3
# coding: utf8
# Should work in both Python 2 and Python 3
from __future__ import unicode_literals
from __future__ import print_function
import io
def iterable_to_stream(iterable, buffer_size=io.DEFAULT_BUFFER_SIZE):
"""
@mechanical-snail
mechanical-snail / linguistics.svg
Created December 23, 2012 05:19
Linguistics community promotion ad for Stack Exchange
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mechanical-snail
mechanical-snail / infinite_dict.py
Created May 19, 2012 22:58
Automatically infinitely-nested defaultdict
#!/usr/bin/env python3
from collections import defaultdict
infinite_dict = lambda : defaultdict(infinite_dict)
@mechanical-snail
mechanical-snail / kittens.js
Created May 16, 2012 06:56 — forked from jasisk/kittens.js
DEATH TO ALL kittens!!!
javascript:(function(){var a=document.getElementsByTagName('img'),i=a.length;while(b=a[--i]){b.setAttribute('src','http://placekitten.com/'+b.width+'/'+b.height);}}());var KICKASSVERSION='2.0';var s = document.createElement('script');s.type='text/javascript';document.body.appendChild(s);s.src='//hi.kickassapp.com/kickass.js';void(0);
@mechanical-snail
mechanical-snail / .gitconfig
Last active October 1, 2015 05:28
gitconfig for managing multiple git identities
[user]
; No default user, lest you start a project as the wrong user.
; You have to specify your identity per-repository, using init-xxx or setuser-xxx.
; @@@@@ TODO: Should actually give an error when trying to commit before specifying an identity.
name = "@@@No user configured@@@"
email = "@@@No user configured@@@"
[alias]
;;;;;; init and user control
@mechanical-snail
mechanical-snail / .gitconfig
Created February 28, 2012 06:37
git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git git
[alias]
; Lets you run "git git git git git git git init", "git ungit echo 'Hello, world!'", etc.
git = !git
ungit = !
@mechanical-snail
mechanical-snail / gist:1911717
Created February 25, 2012 23:48
Draw box in HTML/CSS
<span style="border:1px dotted;display:inline-block;">stuff</span>
@mechanical-snail
mechanical-snail / gist:1911714
Created February 25, 2012 23:47
Vacuum sqlite without running out of disk space
Vacuum sqlite without running out of disk space:
TMPDIR=. sqlite dbfile.sqlite
SQLite version 3.7.2
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> vacuum;
@mechanical-snail
mechanical-snail / start_process.py
Created September 30, 2011 23:43
Wrapper for multiprocessing.Process
from __future__ import print_function
from multiprocessing import Process
def start_process(func):
u"""Decorator that turns the function into a subprocess and starts it asynchronously."""
process = Process(target=func)
process.start()
return process
if __name__ == "__main__":
@start_process