Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / python_template_bench.py
Created May 18, 2012 23:46
Benchmark for Python Template Engine Libraries (Tenjin and Mako)
# -*- coding: utf-8 -*-
###
### benchmark of Tenjin and Mako
###
### usage:
### $ easy_install tenjin
### $ easy_install mako
### $ easy_install benchmarker
### $ python python_template_bench.py -h
@kwatch
kwatch / bench_getframe.py
Created May 27, 2012 04:15
benchmark script to measure cost of sys._getframe(1) and sys._getframe(1).f_locals
# -*- coding: utf-8 -*-
##
## benchmark script to measure cost of sys._getframe(1) and sys._getframe(1).f_locals
##
## How to run:
## $ easy_install benchmarker
## $ python bench_getframe.py -h
## $ python bench_getframe.py -n 1000000 -c 5 -X 1
##
@kwatch
kwatch / gist:2814940
Created May 27, 2012 16:18
Rubyの特殊変数一覧
$! raise された例外オブジェクト
$" require で読み込まれたファイルの配列
$#
$$ 現在のプロセス ID
$%
$& 正規表現にマッチした箇所の文字列
$' 正規表現にマッチした箇所より後ろの文字列
$(
$)
$* Ruby スクリプトに指定された引数。ARGV と同じ
@kwatch
kwatch / gist:3148115
Created July 20, 2012 01:35
Sequenceを作る関数をPythonとRubyで書いてみた
##
## Python
##
def seq(initial, formula):
x = initial
while True:
yield x
x = formula(x)
sequence = seq(1, lambda x: x+1)
@kwatch
kwatch / gist:3154226
Created July 21, 2012 01:52
DSL for routing
route "/users/", :GET=>:index, :POST=>:create
route "/users/new", :GET=>:new
route "/users/:id", :GET=>:show, :PUT=>:update, :DELETE=>:destroy
route "/users/:id/edit", :GET=>:edit
## or
url_path "/users" do
route "/", :GET=>:index, :POST=>:create
route "/new", :GET=>:new
@kwatch
kwatch / gist:3154975
Created July 21, 2012 07:32
もしPythonの内包表記に終了条件が指定できたら
##
## フィボナッチ数列のうち100以下のものを求める
##
def fibgen():
x, y = 0, 1
while True:
yield x
x, y = y, x+y
@kwatch
kwatch / shotenjin.js
Created August 7, 2012 03:36
Shotenjin
/*
* $Release: $
* $Copyright: copyright(c) 2007-2011 kuwata-lab.com all rights reserved. $
* $License: MIT License $
*/
/**
* client-side template engine
*
* usage:
@kwatch
kwatch / example_test.py
Created August 23, 2012 01:43
pyramid.threadlocal.get_current_registry().settingsがうまくとれなくなるサンプル
# -*- coding: utf-8 -*-
"""
pyramid.testing.tearDown()を一度でも実行すると、
pyramid.threadlocal.get_current_registry().settingsが
うまくとってこれなくなることを示すサンプル
"""
import sys
import unittest
@kwatch
kwatch / php55-generator-bench1.php
Created September 12, 2012 22:46
PHP5.5 generator benchmark #1
<?php
///
/// benchmark: loop vs array vs generator vs inner iterator vs closure
///
function create_datafile($filename, $filesize=1024) {
$str = "Haruhi\tFemale\t16\tTeam Leader\n"
. "Mikuru\tFemale\t17\tTime Traveler\n"
. "Yuki\tFemale\t16\tHumanoid Interface\n"
@kwatch
kwatch / php55-generator-bench2.php
Created September 12, 2012 22:52
php5.5 generator benchmark #2
<?php
///
/// generator benchmark
///
function create_datafile($filename, $filesize=1024) {
$str = "Haruhi\tFemale\t16\tTeam Leader\n"
. "Mikuru\tFemale\t17\tTime Traveler\n"
. "Yuki\tFemale\t16\tHumanoid Interface\n"