Skip to content

Instantly share code, notes, and snippets.

##
## enhance form_for(), fields_for(), and fieldset_for() to support :index_by option.
## see:
## http://merb.lighthouseapp.com/projects/7435/tickets/10
##
## this patch is based on merb-helpers 1.0.0.
##
require 'merb-helpers'
##
## parse template with recognizing '#endfor', '#endif', and so on.
##
## ex:
## import tenjin
## from tenjin.helpers import *
## from my_template import MyTemplate
## engine = tenjin.Engine(templateclass=MyTemplate)
## print("------------- script")
## print(engine.get_template("file.pyhtml").script)
# -*- coding: utf-8 -*-
module SelectTagHelper
##
## Generate <select> tag. Both <option> and <opttags> are supported.
##
## ex.
## <% values = {'H'=>'Haruhi', 'M'=>'Mikuru', 'Y'=>'Yuki'} %>
@kwatch
kwatch / gist:800384
Created January 28, 2011 15:29
Example code to benchmark string concatenation in Python
# -*- coding: utf-8 -*-
##
## requires Benchmarker 3.0
## http://pypi.python.org/pypi/Benchmarker/
##
from __future__ import with_statement
from benchmarker import Benchmarker
@kwatch
kwatch / gist:801429
Created January 29, 2011 02:17
Benchmarker example: '+=' v.s. '=' & '+'
# -*- coding: utf-8 -*-
##
## requires Benchmarker 3.0
## http://pypi.python.org/pypi/Benchmarker/
##
from __future__ import with_statement
from benchmarker import Benchmarker, cmdopt
@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]
@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_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_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_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