Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
import glob
import os
import setuptools
import sys
import types
def show_all_files(*args, **kw):
# package files
@dbarnett
dbarnett / jsonalchemy.py
Created February 3, 2012 15:10
JSONAlchemy: Proper JSON marshalling and mutation tracking in SQLAlchemy
import simplejson
import sqlalchemy
from sqlalchemy import String
from sqlalchemy.ext.mutable import Mutable
class JSONEncodedObj(sqlalchemy.types.TypeDecorator):
"""Represents an immutable structure as a json-encoded string."""
impl = String
@dbarnett
dbarnett / cars.py
Created February 11, 2012 07:26
Object-oriented demonstration for SO question http://stackoverflow.com/q/9237725/307705
import random
class Vehicle(object):
def __init__ (self, _id):
self.company = None
self.id = _id
def printDoors(self):
print 'Car ' + str(self.id) + ' has ' + str(self.doors) + ' doors.'
@dbarnett
dbarnett / pip_anyjson.trace
Created February 26, 2012 20:40
snippet from python -m trace --trace pdb install dist/anyjson-0.3.1.tar.gz
This file has been truncated, but you can view the full file.
--- modulename: req, funcname: prepare_files
req.py(898): unnamed = list(self.unnamed_requirements)
req.py(899): reqs = list(self.requirements.values())
--- modulename: req, funcname: values
req.py(754): values_list = []
req.py(755): for key in self._keys:
req.py(757): return values_list
req.py(900): while reqs or unnamed:
req.py(901): if unnamed:
req.py(902): req_to_install = unnamed.pop(0)
"""
Response to
http://venodesigns.net/2010/11/02/emulating-rubys-method_missing-in-python/
If you're going to enumerate each "missing method" and its args, why not just
define a stub?
"""
class Twython(object):
def __init__(self, params):
@dbarnett
dbarnett / .vimrc
Created March 28, 2020 16:18
Sample minimal .vimrc for reproducing vim-codefmt bug xyz
call plug#begin('~/.vim/plugged')
Plug 'google/vim-maktaba'
Plug 'google/vim-codefmt'
Plug 'google/vim-glaive'
call plug#end()
call glaive#Install()