Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / named-group-over-100.py
Created November 2, 2018 04:08
Python < 3.5では、正規表現中のグループ数が100を超えると、エラーが出て正規表現がコンパイルできない。
# -*- coding: utf-8 -*-
import re
arr = []
for i in range(1, 40):
arr.append("^/api/x%02s/(?:\d+)($)" % i)
arr.append("^/api/x%02s/(?:\d+)/edit($)" % i)
arr.append("^/api/x%02s/(?:\d+)/comments($)" % i)
all_rexp= re.compile("|".join(arr)) #=> AssertionError
Title: How to make the fastest Router library in Python
Router is one of the most important feature or component in Web application framework,
ant it is also one of the performance bottlenecks of framework.
In this session, I'll show you how to make router much faster than ever.
* linear search
* prefix search
* regexp concatenation
* regexp optimization
@kwatch
kwatch / ping.md
Last active January 19, 2018 04:59
AWS us-east-1とus-west-2とにpingした結果

AWS us-east-1 (Virginia) にpingした結果

from Tokyo

$ ping -c 10 52.3.228.11
PING 52.3.228.11 (52.3.228.11): 56 data bytes
64 bytes from 52.3.228.11: icmp_seq=0 ttl=39 time=196.512 ms
64 bytes from 52.3.228.11: icmp_seq=1 ttl=39 time=216.174 ms
64 bytes from 52.3.228.11: icmp_seq=2 ttl=39 time=241.810 ms
@kwatch
kwatch / gist:86ea1f20e0d7df65ab43e8300d4e2773
Created April 23, 2017 08:41
pydiet.shを実行したら、約720MB → 約380MB へと半分以下になった
##
## before diet
##
$ du -sk *
91512 2.6.9
109068 2.7.13
117908 3.3.6
115024 3.4.5
142572 3.5.2
@kwatch
kwatch / gist:4dbf5bc8d1d4e973aa8f53630ecd24da
Created January 10, 2017 07:01
71GBのファイルを圧縮: gzip vs bzip2 vs xz vs brotli
$ time gzip -c db_backup.pgdump > db_backup.pgdump.gz
real 34m57.109s
user 34m13.108s
sys 0m38.711s
$ time bzip2 -c db_backup.pgdump > db_backup.pgdump.bz2
real 166m0.206s
user 164m28.035s
@kwatch
kwatch / cal.py
Last active December 26, 2016 05:29
calendar
# -*- coding: utf-8 -*-
from datetime import date, timedelta
class Calendar(object):
def __init__(self, year, month):
self.year = year
self.month = month
@kwatch
kwatch / SkyHigh.nrset
Created December 14, 2016 20:26
~/Library/Kawasemi2/RomajiSettings/SkyHigh.nrset
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ah</key>
<string>ニョ</string>
<key>ai</key>
<string>ヌ</string>
<key>aj</key>
<string>ナ</string>
@kwatch
kwatch / compile_urlpath.py
Created September 23, 2016 14:56
r'/foo/<id:\d+>.json' を r'^/foo(?P<id>\d+)\.json$' へと変換するサンプルコード
# -*- coding: utf-8 -*-
## license: public domain
import re
URLPATH_PARAM_PATTERN = r'<(\w+)(?::(.*?))?>'
re_escape = lambda s: re.escape(s).replace(r'\/', '/')
@kwatch
kwatch / perceptron.py
Last active July 17, 2016 04:47
パーセプトロンのサンプルコード
# -*- coding: utf-8 -*-
##
## 参考: 「Python機械学習プログラミング」
##
## 注: 事前にCSVファイルをダウンロードしておくこと
## $ wget https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
##
@kwatch
kwatch / perceptron_example.py
Last active July 17, 2016 02:22
(obsolete) (ML) Example1
# -*- coding: utf-8 -*-
#from ch02_1 import Perceptron
from perceptron import Perceptron, Perceptron2
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd