Skip to content

Instantly share code, notes, and snippets.

Thomas Ballinger thomasballinger

View GitHub Profile
View browserCanvasCtxFill.html
<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 / Main.elm
Last active Aug 18, 2016
This type error goes away if I switch the order of lines 54 and 55
View Main.elm
module Main exposing (..)
type alias HasXAndY a =
{ a | x : Float, y : Int }
type alias HasX a =
{ a | x : Float }
View composition.py
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"""
View gist:f72c2a4ca5dba8d1b38db33458962ef1
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:
View justnumbers.svg
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 Feb 14, 2016
.py files opened by Python just to start up
View openedByPython.log
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"
View simplecbreak.py
import tty
import termios
import sys
class Cbreak(object):
def __enter__(self):
self.original_stty = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin, termios.TCSANOW)
View simplerserver.py
#!/usr/bin/env python
import socket
listener = socket.socket()
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind(('', 8000))
listener.listen(5)
while True:
View preview.py
def preview(content):
import webbrowser
import tempfile
import time
with tempfile.NamedTemporaryFile(suffix='.html') as f:
f.write(content)
f.flush()
print f.name
webbrowser.open_new_tab('file://'+f.name)
time.sleep(1)
View basic.py
import re
def tokenize(s):
"""
>>> tokenize("(1.1 + 2 * 3)")
['(', '1.1', '+', '2', '*', '3', ')']
"""
return re.findall("[0123456789.a-zA-Z]+|[*+/\-()=]", s)
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.