Skip to content

Instantly share code, notes, and snippets.

View hirokiky's full-sized avatar

Hiroki Kiyohara hirokiky

View GitHub Profile
@hirokiky
hirokiky / wraperrordict.py
Last active August 29, 2015 14:01
Adding methods for django's ErrorDict. (by ugly way). I can't prefigure what will happen by using this. maybe some interfaces are lacking.
class ErrorDict(object):
def __init__(self, errordict):
self.errordict = errordict
def __getitem__(self, item):
return self.errordict[item]
def __setitem__(self, key, value):
self.errordict[key] = value
@hirokiky
hirokiky / lgtm.py
Last active August 29, 2015 14:01
Get a LGHT picture from LGTM.in ramdomly
#! /usr/bin/env python
"""
Get a LGHT picture from LGTM.in ramdomly.
Usage
=====
::
$ ./lgtm.py
import argparse
def parse(args):
parser = argparse.ArgumentParser()
parser.add_argument('--send', choices=['zlib', 'bz2', 'none'], dest='send')
parsed = parser.parse_args(args)
if parsed.send:
return parsed.send
else:
return 'zlib'
@hirokiky
hirokiky / getigoipadic.sh
Last active August 29, 2015 14:00
A bash script to get IPA dictionary for igo.
#!/bin/bash
# This bash script is to get the IPA dictionary for igo,
# allow to morpholigical analysis of Japanese for your project.
# You won't install anything. this script is for just downloading and compiling the dic.
# Actual process for MA is provided by igo-python.
#
# This will do:
# * create 'ipadic' directory here
# * download mecab-ipadic
# * download jar of igo
@hirokiky
hirokiky / xrt.py
Last active August 29, 2015 13:56
Replace inputed contents with spaces on each line like C-x r t of emacs. 4 white-spaces will be inserted by default. But you can change this stirng by specifying '-i' option'.
#! /usr/bin/env python
"""
===
xrt
===
Replace inputed contents with spaces on each line like C-x r t of emacs.
4 white-spaces will be inserted by default.
But you can change this stirng by specifying '-i' option'.
@hirokiky
hirokiky / generate_cache_key.py
Created February 24, 2014 03:47
Generating cache key to correspond to functions and it's arguments.
from hashlib import sha1
def default_key_generator(func, *args, **kwargs):
""" モジュール名、関数名 + 文字列化した引数から生成したsha1をキーとするキャッシュ用キー生成関数
"""
func_identifier = '{func.__module__}:{func.__name__}'.format(func=func)
arg_identifier = 'args:{args}kwargs:{kwargs}'.format(args=args, kwargs=kwargs)
return sha1(func_identifier + '::' + arg_identifier).hexdigest()
@hirokiky
hirokiky / alchemydemo.rst
Last active January 4, 2016 13:39
Tying Mapping class inheritance with SQLAlchemy.

requirements

  • SQLAlchemy==0.9.1
python initialdb.py
python demo.py
@hirokiky
hirokiky / truth_table.py
Last active January 1, 2016 16:09
A truth table ASCII Art generator.
import sys
from itertools import product
def build_truth_table(inputs):
"""
>>> print(build_truth_table(['P', 'Q', 'S']))
P | Q | S |
-------+-------+-------+
True | True | True |
@hirokiky
hirokiky / doc.py
Created November 22, 2013 06:34
removable decorator for python
def removable_decorators(*decorators):
def wrapper(func):
wrapped = reduce(lambda a, b: b(a), reversed(decorators + (func,)))
wrapped.original_func = func
return wrapped
return wrapper
@hirokiky
hirokiky / onelineweb.py
Created November 15, 2013 00:45
One line Web application. Special thanks: @shomah4a
from wsgiref.simple_server import make_server; make_server('', 8888, lambda e, s: [s('200 Ok', []), 'hello'][1]).serve_forever()