Skip to content

Instantly share code, notes, and snippets.

@z0u
z0u / instance_cache.py
Created September 2, 2016 14:39
Just like functools.lru_cache, but creates a new cache for each instance - which is more useful for methods.
def instance_method_lru_cache(*cache_args, **cache_kwargs):
'''
Just like functools.lru_cache, but a new cache is created for each instance
of the class that owns the method this is applied to.
'''
def cache_decorator(func):
@wraps(func)
def cache_factory(self, *args, **kwargs):
# Wrap the function in a cache by calling the decorator
instance_cache = lru_cache(*cache_args, **cache_kwargs)(func)
@z0u
z0u / function_asfrom.py
Created December 1, 2015 23:10
SQLAlchemy workaround for PostgreSQL functions that produce columns
#
# Workaround for unusual PostgreSQL syntax, where functions act like columns.
# Recipe provided by zzzeek (Mike Bayer), author of SA.
# https://bitbucket.org/zzzeek/sqlalchemy/issues/3594/using-text-in-a-join
# https://bitbucket.org/zzzeek/sqlalchemy/issues/3566/figure-out-how-to-support-all-of-pgs#comment-23564706
#
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import functions
from sqlalchemy.sql.elements import ColumnClause
@z0u
z0u / package_bge_runtime.py
Last active November 24, 2022 21:50
Python script to create an executable game by combining a Blender file with the blenderplayer. Asset files can be included; these will not be combined with the executable, but included in the zip archive. The blenderplayer is sourced from a Blender release archive, so multiple platforms can be targeted. To get a release archive, go to: http://ww…
#!/usr/bin/env python3
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
<!doctype html>
<html>
<head>
<script src="lib/jquery/jquery.js"></script>
<script src="lib/jquery/jquery-ui.js"></script>
<script src="lib/jsplumb/jquery.jsPlumb.js"></script>
<script>
$(function() {
jsPlumb.importDefaults({
@z0u
z0u / git-svn-diff.sh
Created February 4, 2012 22:43 — forked from neowulf/git-svn-diff.sh
Creates a patch file between svn branch and git branch
#!/bin/bash
#
# git-svn-diff originally by (http://mojodna.net/2009/02/24/my-work-git-workflow.html)
# modified by mike@mikepearce.net
# modified by aconway@[redacted] - handle diffs that introduce new files
# modified by t.broyer@ltgt.net - fixes diffs that introduce new files
# modified by m@rkj.me - fix sed syntax issue in OS X
# modified by alex@phatcore.com - search for last SVN commit; allow diff
# against non-tracking branch; remove function names on @@ lines.
#