Skip to content

Instantly share code, notes, and snippets.

View wolever's full-sized avatar

David Wolever wolever

View GitHub Profile
@wolever
wolever / patch_objects_get.py
Created November 16, 2010 21:08
Patch `objects.get` so its DoesNotExist errors are more helpful
from functools import wraps
def patch_objects_get(cls):
""" Patch 'cls.objects.get' so its DoesNotExist errors will be more
helpful.
Usage:
>>> @patch_objects_get
... class MyModel(m.Model):
<style>
.result {
width: 35px;
height: 35px;
}
.col-header, .row-header {
font-weight: bold;
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script><![CDATA[
import utils.Timeit;
// Note: this can be found at https://bitbucket.org/wolever/as3-4house/src/tip/src/utils/
var container:Sprite;
function setup():void {
container = new Sprite();
import mock
import y
#
# Incorrect
#
with mock.patch("x.X") as x:
print "x from y:", y.get_x()
print "mocked x:", x
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script><![CDATA[
import mx.charts.AreaChart;
import mx.messaging.Producer;
import utils.Timeit;
import utils.assert;
import utils.cartesian_product;
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script><![CDATA[
import mx.charts.AreaChart;
import mx.messaging.Producer;
import utils.Timeit;
import utils.assert;
import utils.cartesian_product;
import utils.create;
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script><![CDATA[
import mx.charts.AreaChart;
import mx.messaging.Producer;
import utils.Timeit;
import utils.assert;
import utils.cartesian_product;
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script><![CDATA[
import mx.charts.AreaChart;
import mx.messaging.Producer;
import utils.Timeit;
import utils.assert;
import utils.cartesian_product;
import utils.chain;
@wolever
wolever / results.txt
Created April 22, 2011 18:01
Profiling forEach and Array.map in ActionScript
[SWF] Users:wolever:Documents:Adobe Flash Builder 4.5:Test:bin-debug:Test.swf - 718,196 bytes after decompression
running 5 functions 1000 times...
forEachUntyped(int): 3241, 3254, 3225 (min: 3225, drift: 29)
forEachUntyped(ac): 3298, 3352, 3350 (min: 3298, drift: 54)
forEachTypedInt: 3348, 3361, 3409 (min: 3348, drift: 61)
forEachTypedArrayCollection: 3377, 3428, 3415 (min: 3377, drift: 51)
usingMapUntypedFullArgs(int): 4050, 4071, 4070 (min: 4050, drift: 21)
usingMapUntypedIgnoringArgs(int): 9122, 9095, 9098 (min: 9095, drift: 27)
done!
@wolever
wolever / Term.vim
Created May 10, 2011 22:32
Vim command to open Terminal.app at the current file's location
fun! Term()
!term "%:p:h"
endfun
command! Term call Term()