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
// Facebook APIが失敗したときのエラー | |
{ | |
"error": { | |
"message": "Error validating access token: Session has expired at unix time 1359522000. The current unix time is 1359527917.", | |
"type": "OAuthException", | |
"code": 190, | |
"error_subcode": 463 | |
} | |
} |
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 query2sql(query): | |
"""convert query object into non-prepared sql string in SQLAlchemy and psycopg2""" | |
compiler = query.statement.compile() | |
params = compiler.params | |
prepared_sql = compiler.string # or str(compiler) | |
psycopg2_cursor = query.session.connection().connection.cursor() | |
sql = psycopg2_cursor.mogrify(prepared_sql, params) | |
return sql |
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 | |
### | |
### New feature in Pyramid 1.4: '_depth' argument for view_config() | |
### | |
### New argument '_depth' of view_config() in Pyramid 1.4 allows you | |
### to define custome decorator for view methods. | |
### | |
### '_depth' という新しい引数が Pyramid 1.4 から view_cnfig() に加わった。 | |
### これを使うと、ビューメソッド用の独自デコレータが定義できる。 |
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
import unittest | |
from oktest import ok, test | |
class FooTest(unittest.TestCase): | |
@test("'日本語'") | |
def _(self): | |
msg = "日本語" | |
ok (msg) == "にほんご" |
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
require 'erb' | |
sql_template = <<END | |
SELECT | |
FROM users | |
WHERE true | |
% if gender | |
AND gender = :gender | |
% end | |
% if age_min |
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
-- I want to rename column1 and column2 into id and name | |
psql=> values (101, 'Steve'), (102, 'Bill'); | |
column1 | column2 | |
---------+--------- | |
101 | Steve | |
102 | Bill | |
(2 rows) |
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
/* ref: http://lets.postgresql.jp/documents/technical/9.1/1 */ | |
create table members ( | |
id serial primary key | |
, name varchar(255) not null unique | |
, gender char(1) not null -- 'F': female, 'M': male | |
, role varchar(255) | |
); | |
-- Run 'update' statement, or run 'insert' statement when failed. |
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
from sqlalchemy import func | |
from sqlalchemy.types import UserDefinedType, Float | |
class EasyGeometry(UserDefinedType): | |
def get_col_spec(self): | |
return "GEOMETRY" | |
def bind_expression(self, bindvalue): |
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のtestモジュールを消すと、ファイル容量が28MB減った | |
$ du -sk python/2.7.7 | |
95664 python/2.7.7 | |
$ du -sk python/2.7.7/lib/python2.7/test | |
28412 python/2.7.7/lib/python2.7/test | |
$ rm -rf python/2.7.7/lib/python2.7/test/[a-zA-Z1-9]* | |
$ du -sk python/2.7.7 | |
67264 python/2.7.7 | |
$ ruby -e 'p 95664-67264' | |
28400 |
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
## たとえば history.txt の内容がこういう履歴になっていたとして、 | |
bcgf7647 # [john] create 'users' table | |
fdon4243 # [john] add 'birthday' column | |
## alice が 2 件のマイグレーションを追加したとします | |
bcgf7647 # [john] create 'users' table | |
fdon4243 # [john] add 'birthday' column | |
ycii2472 # [alice] change 'birthday' column as not-null |