This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
"""PPSP: Pure Python Server Pages | |
(c) 2016 Yasushi Masuda. | |
""" | |
from collections import OrderedDict | |
from re import compile, M, S | |
# State symbols |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
"""memoserv | |
使い方 | |
起動すると、ローカルホストのポート8000で待ち受けます。 | |
POST すると、サーバに値が保存されます。 | |
GET すると、保存されていた値を返し、消去します。 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import sys | |
from inspect import getinnerframes | |
from functools import wraps | |
from pprint import pprint | |
def inspect_on_failure(msg_fmt): | |
def decorator(func): | |
@wraps(func) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from reportlab.lib.pagesizes import A4 | |
from reportlab.platypus import BaseDocTemplate, Frame, PageTemplate | |
from reportlab.lib.units import mm | |
from reportlab.platypus.flowables import PageBreak, Spacer | |
from reportlab.platypus.paragraph import Paragraph | |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle | |
from reportlab.lib import colors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
coding: utf-8 | |
def answer(relations): | |
"""ハイフンで区切られた語のリストから連関グラフを抽出する | |
""" | |
# 語のペアの集合を生成する | |
pairs = [set(r.split('-')) for r in relations] | |
# pairs に要素が残っている間はループ | |
while pairs: | |
# 起点となるペアを取り出す | |
pivot = pairs.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
>>> from argparse import ArgumentParser | |
>>> from multiprocessing import Process, Queue | |
>>> def build_parser(): | |
... parser = ArgumentParser() | |
... parser.add_argument('-e', '--engage', action='store_true') | |
... parser.add_argument('-b', '--beam-me-up', action='store_true') | |
... parser.add_argument('-d', '--good-day-to-die', action='store_true') | |
... # blah blah blah | |
... return parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from __future__ import print_function | |
from os import walk | |
from os.path import join, splitext | |
from PIL import Image, ImageChops | |
def compare_images(dir1, dir2): | |
for dirname, subdirnames, filenames in walk(dir1): | |
for filename in filenames: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column | |
from sqlalchemy import Integer, DateTime, String, Text | |
from sqlalchemy import UniqueConstraint, Sequence | |
from sqlalchemy import create_engine | |
Base = declarative_base() | |
class SomeTable(Base): | |
__tablename__ = 'some_nice_table' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 汚くて発狂しそう | |
def open_zfiles(filename): | |
open_method = open # builtin open | |
if filename.endswith('gz'): | |
open_method = gzip.open # gzip's open | |
elif filename.endswith('Z'): | |
from subprocess import Popen, PIPE | |
open_method = lambda fn: Popen(['zcat', fn], stdout=PIPE).stdout | |
with open_method(filename, 'rb') as infile: | |
return infile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
"""Mimic legacy BLAST's formatdb to execute BLAST+ makeblastdb command | |
""" | |
import argparse, os, sys | |
def main(): | |
sys.stderr.write('>>>>> %s\n' %(' '.join(sys.argv))) | |
parser = argparse.ArgumentParser() | |
simple_options_map = [ |