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 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() |
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 | |
""" | |
=== | |
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'. |
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
#!/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 |
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
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' |
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 | |
""" | |
Get a LGHT picture from LGTM.in ramdomly. | |
Usage | |
===== | |
:: | |
$ ./lgtm.py |
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
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 |
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 django.db import models | |
class Parent(models.Model): | |
name = models.CharField(max_length=255) | |
def __str__(self): | |
return self.name | |
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
class AcceptMiddleware(object): | |
""" Middleware to add attribute for Accept header of HTTP | |
""" | |
def process_request(self, request): | |
acc = [a.split(';')[0] for a in request.META['HTTP_ACCEPT'].split(',')] | |
setattr(request, 'accepted_types', acc) | |
return None |
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 | |
import string | |
import random | |
alphanumeric = string.ascii_letters + string.digits | |
def main(): | |
return ''.join([random.choice(alphanumeric) for _ in range(8)]) |
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
_some_global_value = 'hoge' | |
class A(object): | |
def __del__(self): | |
global _some_global_value | |
_some_global_value = 'fuga' | |
class B(object): | |
def hoge(self): | |
return _some_global_value |