Skip to content

Instantly share code, notes, and snippets.

# Tail recursion in Python
# http://stackoverflow.com/questions/13591970/does-python-optimize-tail-recursion
# As far as the question, does Python inherently support tail recursion?
# No, and it never will since Guido prefers to be able to have proper tracebacks
# http://neopythonic.blogspot.com.au/2009/04/tail-recursion-elimination.html
# http://neopythonic.blogspot.com.au/2009/04/final-words-on-tail-calls.html
# But it's possible to do it with a decorator, and the stack never gets too deep.
# http://code.activestate.com/recipes/496691-new-tail-recursion-decorator/
@wware
wware / JOINs_in_MySQL.sql
Last active August 29, 2015 13:58
I never remember this JOIN database stuff unless I have a reminder like this.
-- These examples are from http://en.wikipedia.org/wiki/Join_(SQL)
DROP DATABASE IF EXISTS dumb_example;
CREATE DATABASE dumb_example;
USE dumb_example;
CREATE TABLE department
(
DepartmentID INT,
DepartmentName VARCHAR(20)
@wware
wware / symbol.ps
Last active December 22, 2015 10:08
Postscript code to make a cleaner version of the vacuum tube artist-previously-known-as symbol
% http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF
/xcenter 306 def
/ycenter 500 def
/scalefactor 8 def
/scale1 {
scalefactor mul
} def
@wware
wware / grok_mock.py
Last active May 18, 2021 15:18
I find mock confusing and mystical. Here is some clarification.
"""
Mock is confusing as hell. Document some of it.
http://www.voidspace.org.uk/python/mock/patch.html
http://mock.readthedocs.org/en/latest/index.html
"""
import unittest
import pprint
from mock import MagicMock, patch, call
@wware
wware / debuggy_thinger.py
Last active December 15, 2015 22:58
Handy debug thing for logging the entry and exit of functions and methods, showing arguments and return values. I found this useful for seeing how things work in an unfamiliar library (in this case, django-haystack).
import logging
import sys
import types
# It's great to log the entering/leaving of methods and functions, but it would be way cool
# to see who gets called by the function you go into. That probably means hacking ASTs and
# finding the GOSUB bytecode.
def discover(obj, filtfunc=None):
if filtfunc is None: