Skip to content

Instantly share code, notes, and snippets.

class FailingFieldFixture(object):
def setUp(self):
self.field = InitialField(full_name=self.full_name, max_length=4)
def test_validation_fails(self):
with self.assertRaises(ValidationError):
self.clean = self.field.clean(self.value)
class WhenFirstInitialIsWrong(FailingFieldFixture, TestCase):
class BetterJSONEncoder(json.JSONEncoder):
"""`Decimal`-aware JSONEncoder"""
ROUNDING_DECIMAL = decimal.Decimal('0.01')
def default(self, o):
if isinstance(o, decimal.Decimal):
return str(o.quantize(BetterJSONEncoder.ROUNDING_DECIMAL))
return json.JSONEncoder.default(self, o)
@gaconnet
gaconnet / des_in_cbc_mode.go
Created December 15, 2010 20:52
I must be using NewCBCEncrypter & NewCBCDecrypter incorrectly
// Example run:
// $ ./main
// key[373b91dcef162a641052f4fd8f0df10e0e1a1f67feefd01c] -- 24
// iv[0000000000000000] -- 8
// 0102030405060708 -- 8
// 45f7fa13d05b4045 -- 8
// 0000000000000000 -- 8
// -- 0
func main() {
// file: one_a.c
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include "one_b.c"
// Compile:
// gcc -Wall -std=c99 one_a.c
#!/usr/bin/env python
foo = 'Hello'
def frob():
print "FOO 1", foo
def fish():
global foo
syntax enable
filetype plugin indent on
set hls
set nobackup
set noautoindent nosmartindent
set tabstop=4 shiftwidth=4 softtabstop=4 expandtab
setlocal spell spelllang=en_us
set guioptions-=m
set guioptions-=T
def retry_until_successful(function_to_repeatedly_try):
while True:
try:
function_to_repeatedly_try()
except:
print 'EXCEPTION RACHEL-SAN!'
continue
break
def add_listing(url, price):
# .bashrc
# source: http://www.ukuug.org/events/linux2003/papers/bash_tips/#S20
function qgit {
command qgit --all "$@" &
}
#include <stdio.h>
// Abstract vs. Concrete
//
// Compile:
// gcc -Wall -std=c99 unsigned.c
// Run:
// ./a.out
int main(void) {