Skip to content

Instantly share code, notes, and snippets.

View aodag's full-sized avatar

Atsushi Odagiri aodag

View GitHub Profile
import sqlalchemy as sa
import sqlalchemy.orm as orm
from sqlalchemy.orm import class_mapper, exc as orm_exc
def query_property(db_session, query_cls=None):
class query(object):
def __get__(s, instance, owner):
try:
mapper = class_mapper(owner)
if mapper:
@aodag
aodag / bankaccount.py
Created March 16, 2013 02:59
bankaccount test tutorial
import sys
import logging
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
handler = logging.FileHandler("bank.log", )
handler.setLevel(logging.ERROR)
logger.addHandler(handler)
import logging
import tulip
logging.basicConfig(level=logging.DEBUG)
class EchoProtocol(tulip.Protocol):
def connection_made(self, transport):
self.transport = transport
logging.info("connection_made: {0}".format(transport))
@aodag
aodag / sources.list
Created July 5, 2013 06:39
mint upgrade
# deb http://packages.linuxmint.com/ maya main upstream import
# deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
# deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
# deb http://security.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse
# deb http://archive.canonical.com/ubuntu/ precise partner
# deb http://packages.medibuntu.org/ precise free non-free
# deb http://packages.linuxmint.com/ nadia main upstream import
# deb http://archive.ubuntu.com/ubuntu/ quantal main restricted universe multiverse
# deb http://archive.ubuntu.com/ubuntu/ quantal-updates main restricted universe multiverse
import os
import distlib.wheel
from paver.easy import *
here=os.path.dirname(__file__)
options(
here=here,
wheeldir=os.path.join(here, "dists"),
)
@aodag
aodag / pavement.py
Created September 21, 2013 18:20
標準unittestのdiscoverでcoverageをとる
import unittest
import coverage
here = os.path.dirname(__file__)
@task
def test(options):
""" run tests
"""
cov = coverage.coverage(source=options.test['source'])
@aodag
aodag / development.ini
Last active December 24, 2015 13:29
複数アプリの設定を書く例
[app:admin]
paste.app_factory = your.app.admin:main
[app:site]
paste.app_factory = your.app.user:main
[server:admin]
use = egg:waitress
port = 8080
@aodag
aodag / topological_sort.py
Created October 20, 2013 13:07
トポロジカルソートを手習い的に実装
"""
http://ja.wikipedia.org/wiki/トポロジカルソート
"""
nodes = [
7,
5,
3,
11,
8,
@aodag
aodag / pavement.py
Created October 21, 2013 13:04
distlibで依存ライブラリとexportsをreSTで表示
@task
def freeze():
dist_path = distlib.database.DistributionPath()
print()
print('.. contents::')
print()
for d in dist_path.get_distributions():
print()
print("{dist.name} = {dist.version}".format(dist=d))
print("=" * 80)
# In mymodule.py
from zope.proxy import ProxyBase, setProxiedObject
hoge = ProxyBase(None)
def setup_hoge():
setProxiedObject(hoge, 'hoge')