Skip to content

Instantly share code, notes, and snippets.

<html>
<body>
<canvas id="canvas1" width="200" height="200"></canvas>
<canvas id="canvas2" width="200" height="200"></canvas>
<canvas id="canvas3" width="200" height="200"></canvas>
<script>
var canvases = [canvas1, canvas2, canvas3]
var fillArgs = [undefined, 'evenodd', 'nonzero']
@thomasballinger
thomasballinger / gist:5807241
Created June 18, 2013 17:01
Simple WSGI server and app
import socket
# see wsgiref.simple_server for a real implementation of a WSGI server
def serve(app):
listener = socket.socket()
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind(('', 8080))
listener.listen(5)
while True:
s, addr = listener.accept()
@thomasballinger
thomasballinger / Main.elm
Last active August 18, 2016 23:54
This type error goes away if I switch the order of lines 54 and 55
module Main exposing (..)
type alias HasXAndY a =
{ a | x : Float, y : Int }
type alias HasX a =
{ a | x : Float }
from typing import Callable
class A: pass
class B: pass
class C: pass
def composition(aToB: Callable[[A], B],
bToC: Callable[[B], C]) -> Callable[[A], C]:
"""Returns a callable that takes an A and returns a C"""
a simple remix file format
Files are always UTF-8
a syntax like
episode <episode query> of <podcast url>
play from <time> to <time> [at 2x speed] [at +12 dB]
example:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thomasballinger
thomasballinger / openedByPython.log
Created February 14, 2016 01:45
.py files opened by Python just to start up
tomb@localhost:~$ strace python myPythonScript.py 2>&1 >/dev/null | grep open | grep -v ENOENT | grep -o '".*"' | grep -v '\.pyc'
"/etc/ld.so.cache"
"/lib/x86_64-linux-gnu/libpthread.so.0"
"/lib/x86_64-linux-gnu/libc.so.6"
"/lib/x86_64-linux-gnu/libdl.so.2"
"/lib/x86_64-linux-gnu/libutil.so.1"
"/lib/x86_64-linux-gnu/libz.so.1"
"/lib/x86_64-linux-gnu/libm.so.6"
"/usr/lib/python2.7/site.py"
"/usr/lib/python2.7/os.py"
@thomasballinger
thomasballinger / ttt.py
Created January 23, 2014 00:17
Examples of Python syntax
"""An immutable Tic Tac Toe board and minimax ai"""
import itertools
class Board(object):
"""Immutable Tic Tac Toe board
>>> Board().rows
((' ', ' ', ' '), (' ', ' ', ' '), (' ', ' ', ' '))
>>> print Board()
| |
@thomasballinger
thomasballinger / opt.py
Created December 23, 2013 23:27
bpython pastebin script: uploads to Online Python Tutor
#!/usr/bin/env python
# Add the line
# pastebin_helper = opt.py
# to .bpython/config
# under a section called
# [general]
# to enable
import sys
import urllib
@thomasballinger
thomasballinger / created_at.rb
Created December 19, 2013 17:04
Add "created_at" to all ruby objects
class Class
alias :create :new
@@objects = []
def new(*a, &b)
obj = allocate
if obj.class == String
nil
elsif obj.class == Time