Skip to content

Instantly share code, notes, and snippets.

View aodag's full-sized avatar

Atsushi Odagiri aodag

View GitHub Profile

>>> import argparse >>> >>> def split_type(s): ... if ":" in s: ... return tuple(s.split(":", 1)) ... else: ... return s, 'zlib' ... >>> parser = argparse.ArgumentParser() >>> parser.add_argument('--send', type=split_type)

@aodag
aodag / main.py
Created May 6, 2014 10:34
restful-json wsgi app
import functools
from sqlalchemy import (
Column,
Integer,
ForeignKey,
Unicode,
)
from sqlalchemy.orm import (
scoped_session,
sessionmaker,
@aodag
aodag / app.py
Created May 15, 2014 17:35
aiohttpとaiopgを使ってasync web+dbアプリケーション
# -*- coding:utf-8 -*-
import io
import argparse
import asyncio
import aiopg
import sqlalchemy as sa
import webob
from aiopg.sa import create_engine
from aiohttp.wsgi import WSGIServerHttpProtocol
from webdispatch import URLDispatcher, MethodDispatcher
<ul>
{% for commit in commits %}
<li>
{{ commit.id}} {{ commit.message }}
</li>
{% endfor %}
</ul>
@aodag
aodag / run
Last active August 29, 2015 14:08
reSTから、LuaLaTeXでフォント埋め込み、しおり付の日本語なPDFを作るためのtexに変換するオプション
rst2latex --documentclass=ltjsbook --hyperref-options="unicode=true" --latex-preamble="\usepackage[ipa]{luatexja-preset}" book.rst book.tex
lualatex book.tex
@aodag
aodag / REDME.rst
Last active August 29, 2015 14:10
colanderでDB絡みのチェックをかけるバリデータの検討

使い方の想定

schema.bind(query=DBSession.query(Person).filter(Person.gender=='male')
           col=Person.first_name + " " + Person.last_name)
Babel==1.3
Mako==1.0.0
MarkupSafe==0.23
Pillow==2.6.1
SQLAlchemy==0.9.8
WebDispatch==1.3
WebHelpers2==2.0rc2
WebOb==1.4
WebTest==2.0.16
beautifulsoup4==4.3.2

リストたちを入れる箱を作る

>>> values = {}

いろんな名前で空のリストを作る >>> varname = ('t1', 't2', 't3') >>> for vn in varname: ... values[vn] = [] ...

@aodag
aodag / part_seq.py
Created January 14, 2015 01:01
先頭からN個ずつの要素でスライスしていくジェネレータ: itertoolsにありそうなのにないっぽい
def part_seq(seq, num):
"""
>>> list(part_seq(range(10), 5))
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
>>> list(part_seq(range(10), 3))
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
"""
s = seq
while s:
f, s = s[:num], s[num:]
@aodag
aodag / main
Created February 2, 2015 06:44
virtualenvなしで vendorディレクトリをパッケージインストール先にして実行してみる例
$ pip install -t vendor webob webdispatch jinja2
Collecting webob
Downloading WebOb-1.4.tar.gz (633kB)
100% |################################| 634kB 5.5MB/s
Collecting webdispatch
Downloading WebDispatch-1.3-py2.py3-none-any.whl
Collecting jinja2
Downloading Jinja2-2.7.3.tar.gz (378kB)
100% |################################| 380kB 6.0MB/s
Collecting markupsafe (from jinja2)