Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / calendar1.py
Created February 27, 2015 04:17
1ヶ月分のカレンダーを表示する(その1)
# -*- coding: utf-8 -*-
import sys
try:
xrange
except NameError:
xrange = range
@kwatch
kwatch / example.php
Created February 14, 2015 02:47
HTMLテンプレートにどんな変数を渡したかをわかりやすくするための工夫 in PHP
###
### templating.php
###
<?php
function h($str) {
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
}
function print_template($template_filename, $vars) { ## テンプレートへの値は連想配列$varsで渡す
@kwatch
kwatch / gist:4ca709d9df898a3473e4
Last active August 29, 2015 14:13
関数 sum() を、ループと、再帰と、末尾再帰でそれぞれ書いたサンプルコード(Python)。末尾再帰のわかりにくさが目立つ。
## ループ
def sum(xs):
t = 0
for x in xs:
t += x
return t
## 再帰呼び出し
def sum(xs):
if not xs:
@kwatch
kwatch / postgresql-book-fix.yaml
Last active May 27, 2017 04:53
書籍『内部構造から学ぶPostgreSQL - 設計・運用計画の鉄則』の気付いた点
# -*- coding: utf-8 -*-
- page: 55
text: "暗号化したパスワード文字列を送信する「md5」方式"
comment: MD5 はハッシュ値を計算するだけであり、暗号化するわけではないのでは?
- page: 69
item: 表4-3
text: "同時に実行されている他のトランザクションが書き込んでいるがコミットされていないデータを読み込んでしまう"
comment: "同時に実行されている他のトランザクションが、書き込んでいるがコミットされていないデータを読み込んでしまう"
@kwatch
kwatch / matching.py
Created September 15, 2014 11:07
Implementation of re.matching()
# -*- coding: utf-8 -*-
import re
class matching(object):
def __init__(self, string):
self.string = string
self.matched = None
@kwatch
kwatch / bench3.py
Created September 14, 2014 06:53
str.isdigit() と re.match() のベンチマーク
# -*- coding: utf-8 -*-
import sys, re
from benchmarker import Benchmarker
try:
xrange
except:
xrange = range
@kwatch
kwatch / bench2.py
Created September 14, 2014 06:52
str.endswith() と re.search() のベンチマーク
# -*- coding: utf-8 -*-
import sys, re
from benchmarker import Benchmarker
try:
xrange
except:
xrange = range
@kwatch
kwatch / bench1.py
Last active August 29, 2015 14:06
str.startswith() と re.match() のベンチマーク
# -*- coding: utf-8 -*-
import sys, re
from benchmarker import Benchmarker
try:
xrange
except:
xrange = range
@kwatch
kwatch / config-example.js
Created August 20, 2014 11:52
__proto__ を活用した、環境別設定オブジェクト
// -*- coding: utf-8 -*-
// ベースとなる設定
var config_common = {
name: 'My Application',
mode: null,
secret: null,
db: {
host: 'localhost',
port: 9876,
@kwatch
kwatch / value-object-example.js
Last active August 29, 2015 14:05
数値や文字列をラップしたValueクラスを作るサンプル
function Length(value, uom) {
this.value = value;
this.uom = uom || "cm";
}
function Square(length, uom) {
this.length = new Length(length, uom);
}
function Colored(figure, r, g, b) {