Skip to content

Instantly share code, notes, and snippets.

@keturn
keturn / README.markdown
Created May 25, 2011 22:51
playing with canvas and sierpinski

Canvas Experiment: Sierpinski Triangles

This is just a little doodle for me to get a feel for how the HTML5 canvas element can be used. The canvas is a pixel-based sort of thing, and so maybe not well suited to applications that want scalable elements or independent moving parts; there SVG might be a better choice. But for uses where you want to fiddle with a lot of pixels, where it'd be undesirable to make a new object for every point you manipulate, canvas fits the bill.

@keturn
keturn / test_handler.py
Created June 16, 2011 23:47
another "Am I doing this wrong?" case of unit tests for a web controller
# test case using fudge 0.9.x for fakes.
class TestUploadList(TestCase):
@with_fakes
def test_upload(self):
"""Upload is converted and JSON returned.
"""
self.req = Fake("Request").has_attr(variables={})
content = "UPLOADED STUFF"
@keturn
keturn / gist:1061054
Created July 2, 2011 16:18
evolution fail on Migrating local user data
# Not sure exactly what the problem is here, or how to make a useful bug report out of it without sending off
# my entire ~/.evolution directory (which is both large and contains sensitive data).
# Version: 2.32.2-0ubuntu7
$ evolution &
Tracker-Message: Registering D-Bus service...
Name:'org.freedesktop.Tracker1.Miner.Emails'
Tracker-Message: Registering D-Bus object...
Tracker-Message: Path:'/org/freedesktop/Tracker1/Miner/Emails'
Tracker-Message: Object Type:'TrackerEvolutionPlugin'
@keturn
keturn / gist:1121192
Created August 2, 2011 20:51
why is my wifi terrible?
client is ubuntu Lucid 10.04 LTS with updates, access point is an Airport Express of some sort.
$ ping -c 100 192.168.1.102 # this is the nameserver
--- 192.168.1.102 ping statistics ---
100 packets transmitted, 46 received, 54% packet loss, time 99207ms
rtt min/avg/max/mdev = 0.997/299.866/2064.793/466.158 ms, pipe 3
$ ping -c 100 192.168.1.1 # this is the router
--- 192.168.1.1 ping statistics ---
@keturn
keturn / assert_composite.py
Created August 10, 2011 20:13
asserting a function is a composite function
"""An example for discussion on "Fixing Untestable Code Sequences"
http://arlobelshee.com/post/mock-free-example-part-3-fixing-untestable-code-sequences
"""
from twisted.trial.unittest import TestCase
class ParserDoodle(object):
def parseCharacterIntoCards(self):
for powerElement in self.findAllPowers():
@keturn
keturn / hgrdiff.sh
Created October 13, 2011 19:13
hg repository diff
#!/bin/bash
# diff working copy of two mercurial repositories.
# Only include tracked files.
# Adapted from http://mercurial.selenic.com/wiki/GenerateDiffBetweenRepositories
if [ $# -eq 1 ] ; then
SRC=$PWD
DEST=$1
elif [ $# -eq 2 ] ; then
SRC=$1
DEST=$2
<p>Something <a href="https://priv.ly/posts/276?burntAfter=1340935994&random_token=bae8874208">blah </a>
@keturn
keturn / nestedFuncs.py
Created August 9, 2012 18:28
python shadowing variables in inner scopes
def foo(a):
print "foo a", a
def bar(x):
print "bar reading a", a
def baz(x):
a = x
print "baz wrote to a", a
def quux(x):
@keturn
keturn / warppointer.py
Created July 4, 2010 06:07
xwarppointer python script
#!/usr/bin/env python
"""Make the X cursor wrap-around.
Adapted from http://appdb.winehq.org/objectManager.php?sClass=version&iId=12599
to work around lack of relative mouse movement http://wiki.winehq.org/Bug6971
for Thief: Dark Shadows (and possibly others)
This version is a little kinder to your CPU than the shell script with
the busy-loop that starts a new process for every pointer query.
"""
@keturn
keturn / dunder_str_unicode.py
Last active November 11, 2015 21:05
the perils of returning unicode from __str__ in Python 2 compatible code
# -*- coding: utf-8 -*-
from django.utils.encoding import force_str
class BadStr(object):
def __init__(self, content):
self.content = content
def __str__(self):
assert isinstance(self.content, unicode), "returning it from __str__ anyway"