This file contains hidden or 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
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 |
This file contains hidden or 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
## | |
## Python | |
## | |
def seq(initial, formula): | |
x = initial | |
while True: | |
yield x | |
x = formula(x) | |
sequence = seq(1, lambda x: x+1) |
This file contains hidden or 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
$! raise された例外オブジェクト | |
$" require で読み込まれたファイルの配列 | |
$# | |
$$ 現在のプロセス ID | |
$% | |
$& 正規表現にマッチした箇所の文字列 | |
$' 正規表現にマッチした箇所より後ろの文字列 | |
$( | |
$) | |
$* Ruby スクリプトに指定された引数。ARGV と同じ |
This file contains hidden or 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 -*- | |
## | |
## 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 | |
## |
This file contains hidden or 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 -*- | |
### | |
### benchmark of Tenjin and Mako | |
### | |
### usage: | |
### $ easy_install tenjin | |
### $ easy_install mako | |
### $ easy_install benchmarker | |
### $ python python_template_bench.py -h |
This file contains hidden or 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
def setdefault(obj, name, value): | |
if hasattr(obj, name): | |
return getattr(obj, name) | |
else: | |
setattr(obj, name, value) | |
return value |
This file contains hidden or 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
## | |
## simulate multi-indeces with tuple, without paren | |
## | |
class Foo(object): | |
def __getitem__(self, index): | |
return index | |
if __name__ == '__main__': |
This file contains hidden or 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 -*- | |
<%! | |
## | |
## This is an alternative template file for pyramid_debugtoolbar. | |
## Using this template, you can open errored file very quickly. | |
## | |
## | |
## Usage: | |
## |
This file contains hidden or 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
$ pserve development.ini --reload | |
Starting subprocess with file monitor | |
/Users/kwatch/myproj1/local/lib/python2.7/site-packages/SQLAlchemy-0.7.5-py2.7-macosx-10.4-x86_64.egg/sqlalchemy/ext/declarative.py:1336: SAWarning: The classname 'AdminUser' is already in the registry of this declarative base, mapped to <class 'smapo.common.models.base.AdminUser'> | |
_as_declarative(cls, classname, cls.__dict__) | |
Traceback (most recent call last): | |
File "/Users/kwatch/myproj1/local/bin/python2.7/pserve", line 9, in <module> | |
load_entry_point('pyramid==1.3b2', 'console_scripts', 'pserve')() | |
File "/Users/kwatch/myproj1/local/lib/python2.7/site-packages/pyramid-1.3b2-py2.7.egg/pyramid/scripts/pserve.py", line 47, in main | |
return command.run() | |
File "/Users/kwatch/myproj1/local/lib/python2.7/site-packages/pyramid-1.3b2-py2.7.egg/pyramid/scripts/pserve.py", line 290, in run |
This file contains hidden or 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
@view_config(route_name='user_new', request_method='GET', renderer='form.html') | |
def user_new(request): | |
# ... | |
@view_config(route_name='user_create', request_method='POST', renderer='form.html') | |
def user_crate(request): | |
# ... | |
... |