Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / 15puzzle.html
Last active December 16, 2015 00:18
15puzzle.html
<html>
<head>
<meta charset="utf-8" />
<title>15 Puzzle</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<div id="main-content">
<table id="puzzle">
<tbody>
# -*- coding: utf-8 -*-
###
### Benchmark: http://cocodrips.hateblo.jp/entry/2015/10/11/114212#問題2
###
from benchmarker import Benchmarker
try:
xrange
@kwatch
kwatch / bench_zerofill.py
Created November 11, 2015 14:09
Benchmark: create a list object filled by zero
# -*- coding: utf-8 -*-
###
### Benchmark: create a list object padding by zero
###
from benchmarker import Benchmarker
try:
xrange
@kwatch
kwatch / bench1.rb
Last active January 7, 2016 10:50
Ruby on Rails, Sinatra, Rack+Request+Response, Keight.rb のベンチマークスクリプト
# -*- coding: utf-8 -*-
require 'sinatra/base'
require 'rack'
require 'rack/protection'
require 'rack/protection/frame_options'
require 'rack/protection/http_origin'
require 'rack/protection/ip_spoofing'
require 'rack/protection/json_csrf'
require 'rack/protection/path_traversal'
@kwatch
kwatch / sample.py
Created September 11, 2015 01:16
Pythonでは条件によってブロックをスキップするような構文がない
@on('POST', '/foobar')
def do_post(self):
do_something1()
do_something2()
## 残念ながら Python ではブロックをスキップする機能が
## ないのでこれは使えない
with invoke('new_cool_feature_name'):
old_feature1()
old_feature2()
## なので、decoratorをhiger order functionの
@kwatch
kwatch / template_manager.py
Created September 5, 2015 03:01
テンプレートオブジェクトをキャッシュするサンプルコード
# -*- coding: utf-8 -*-
###
### テンプレートオブジェクトをキャッシュするサンプルコード
###
from os.path import getmtime
class TemplateError(Exception):
@kwatch
kwatch / dom.js
Created August 17, 2015 14:45
very small DOM builder using wabi-sabi style
/// # -*- coding: utf-8 -*-
///
/// very small DOM builder using wabi-sabi style
///
/// Example:
///
/// var a = dom(["a", {href: "/link"}, "Link"]);
/// console.log(a);
/// //=> <a href="/link">Link</a>
@kwatch
kwatch / gist:fe96d6c13cd3c7d12c89
Last active August 29, 2015 14:23
SQLAlchemyで、条件を動的に追加するときの書き方
##
## SQLAlchemyで、条件を動的に追加するときの書き方
##
##
## before
##
q = db.query(Model) \
.filter(Model.created_at >= date(2015, 6, 1)
if kind:
# -*- coding: utf-8 -*-
import re, random
from sqlalchemy.exc import IntegrityError
from smapo.common.models.event import EventOperation
from smapo.common.models.base import (
DBSession, RedirectPage, RedirectUniqueCode, UserActionHistory,
)
@kwatch
kwatch / calendar2.py
Last active August 29, 2015 14:16
1ヶ月分のカレンダーを表示する(その2)
# -*- coding: utf-8 -*-
import sys
try:
xrange
except NameError:
xrange = range