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 re | |
import os | |
def main(): | |
regex = re.compile(r'(COURSE_LEC_DETAIL_URL.*?) % APP_BASE\)', re.S) | |
for dirpath, dirnames, filenames in os.walk('./settings'): | |
for base in [x for x in filenames if x.endswith('.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
# -*- coding:utf-8 -*- | |
# except ???, ** という構文がエラーになった | |
# raise Exception, 'NG' # python2は使えるけど、3はSyntaxError | |
try: | |
raise Exception('Not found.') | |
except Exception as ex: | |
print(ex) |
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 flatten(L): | |
stack, tmp = [L], None | |
while stack: | |
tmp = stack.pop(-1) | |
while tmp: | |
x = tmp.pop(0) | |
if not hasattr(x, '__iter__'): |
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 flatten(L): | |
'''入れ子のリストもすべて掘り下げてflatにする''' | |
for x in L: | |
if hasattr(x, '__iter__'): | |
for y in flatten(x): | |
yield y | |
else: |
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 deeplist(args): | |
depth, items = len(args), list(args) | |
result = L = [] | |
while depth > 0: | |
x = [items.pop(0)] | |
L.append(x) | |
L = x |
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 random | |
def main(text, n): | |
length = len(text) | |
count = int(length * n / 10) | |
sample = random.sample(range(length), count) | |
L = list(text) | |
for i in sample: |
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 string | |
U = string.ascii_uppercase | |
def to_s(number): | |
'''数値をアルファベット文字列に変換する。 | |
>>> to_s(1) |
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
[user] | |
name = oyakata | |
email = [email protected] | |
[core] | |
excludesfile = $HOME/.gitignore | |
editor = vim -c \"set fenc=utf-8\" | |
[merge] | |
ff = false | |
[alias] | |
ci = commit |
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 zlib | |
def rate(bin, size): | |
compressed = len(zlib.compress(bin)) | |
return float(compressed) / float(size) | |
KB = 1024 |
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
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
sleeping... |