Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / gist:1319756
Created October 27, 2011 14:51
Example to instanciate and manipulate recipe object in pyKook 0.6.0
## define generic recipe
@recipe('*.cmo', ['$(1).ml', '$(1).cmi'])
def file_cmo(c):
system(...)
## create specific recipe object for 'a.cmo' from generic recipe
a_cmo_recipe = kookbook['a.cmo']
## manipulate recipe object, for example append dependency
a_cmo_recipe.ingreds.append('b.cmi')
@kwatch
kwatch / gist:1088503
Created July 18, 2011 03:42
simulate named_scope by higher-order function + partial application in Python
##
## named_scope example in Rails2
## (http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-finder-functionality)
##
class User < ActiveRecord::Base
named_scope :active, :conditions => {:active => true}
named_scope :recent, lambda { { :conditions => ['created_at > ?', 1.week.ago] } }
end
# same as User.find(:all, :conditions => {:active => true})
@kwatch
kwatch / whats-new-python320.ja.rst
Created April 6, 2011 23:24
What's New in Python 3.2 translation to Japanese

What's New In Python 3.2

Author: Raymond Hettinger
Release:|release|
Date: |today|
@kwatch
kwatch / python-3.2-whatsnew-pep3333.rst
Created April 4, 2011 23:06
Python 3.2 What's New での、PEP3333 セクションの日本語訳

PEP 3333: Python Web Server Gateway Interface v1.0.1

This informational PEP clarifies how bytes/text issues are to be handled by the WGSI protocol. The challenge is that string handling in Python 3 is most conveniently handled with the :class:`str` type even though the HTTP protocol is itself bytes oriented.

この情報提供のための PEP は、WSGI プロトコルにおいてバイト/テキストの問題がどう扱われるべきかを明確にする。

@kwatch
kwatch / gist:900037
Created April 3, 2011 00:12
social buttons for Hiki template (hiki/template/view.html)
<% unless @conf.base_url =~ /\.RubiMa/ %>
<!-- social-buttons -->
<div class="social-buttons" style="text-align:right">
<!-- hatena bookmark button -->
<a href="http://b.hatena.ne.jp/entry/<%= @conf.base_url.sub(/^https?:\/\//, '') %>?<%= @conf.options['page'] %>" class="hatena-bookmark-button" title="Add this entry to Hatena Bookmark"><img src="http://b.st-hatena.com/images/entry-button/button-only.gif" alt="Add this entry to Hatena Bookmark" width="20" height="20" style="border: none;" /></a>
<script type="text/javascript" src="http://b.st-hatena.com/js/bookmark_button.js" charset="utf-8"></script>
<!-- delicious bookmark button -->
<a href="http://delicious.com/save" onclick="window.open('http://www.delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;"><img src="http://static.delicious.com/img/delicious.gif" alt="Delicious" style="border:none" /></a
@kwatch
kwatch / bench_nested_query.rb
Created March 2, 2011 03:15
benchmark to measure parsing both 'user[123][name]' and 'user.123.name'
###
### benchmark to measure parsing both 'user[123][name]' and 'user.123.name'
###
require 'rubygems'
require 'benchmarker'
## copied from rack/utils.rb
@kwatch
kwatch / bench_parse_qs.rb
Created March 2, 2011 03:12
benchmark to measure CGI::parse()
# -*- coding: utf-8 -*-
###
### benchmark to measure CGI::parse()
###
require 'rubygems'
require 'benchmarker'
@kwatch
kwatch / bench_escape_html.rb
Created March 2, 2011 03:06
benchmark to measure both h() and escape_html()
###
### benchmark to measure both h() and escape_html()
###
require 'rubygems'
require 'benchmarker'
ESCAPE_ = {
'&' => '&amp;',
'<' => '&lt;',
@kwatch
kwatch / bench_cgi.rb
Created March 2, 2011 03:01
benchmark to measure cgi program
###
### benchmark to measure cgi program
###
require 'rubygems'
require 'benchmarker'
def cgi_file(file_name, content)
File.open(file_name, 'wb') do |f|
@kwatch
kwatch / bench_require.rb
Created March 2, 2011 02:56
benchmark to measure library loading time
###
### benchmark to measure library loading times.
###
require 'rubygems'
require 'benchmarker'
targets = %w[cgi cgi/session erb tempfile tmpdir openssl
logger pathname pstore time date2 uri drb fileutils
rss rexml/document yaml psych rubygems]