Skip to content

Instantly share code, notes, and snippets.

helpers do
include Rack::Utils
alias_method :h, :escape_html
end
require 'rubygems'
require 'sinatra'
get '/' do
response['Last-Modified'] = 'SpongeBobSquarePants'
'If-Modified-Since: ' + request.env['HTTP_IF_MODIFIED_SINCE']
end
require 'rubygems'
require 'sinatra'
get '/' do
response['Last-Modified'] = 'SpongeBobSquarePants'
"If-Modified-Since: #{request.env['HTTP_IF_MODIFIED_SINCE']}"
end
def defer(&block)
def block.each ; yield call ; end
block
end
app =
lambda do |env|
status = 200
headers = { 'Last-Modified' => exec_sql('SELECT MAX(updated_at) FROM foos').httpdate }
@rtomayko
rtomayko / gist:13682
Created September 29, 2008 21:40 — forked from entp/gist:13681
<!-- for some reason this isn't receiving my style! -->
<pre class="tl-body viewsource"><%= foo.bar %></pre>
<!-- duh -->
" ---------------------------------------------------------------------------
" Strip all trailing whitespace in file
" ---------------------------------------------------------------------------
function! StripWhitespace ()
exec ':%s/ \+$//gc'
endfunction
map ,s :call StripWhitespace ()<CR>
@rtomayko
rtomayko / gist:21747
Created November 2, 2008 20:48
tomayko.com Rack::Cache configuration
# from tomayko.com.ru (rackup file)
# tomayko.com Rack::Cache configuration
use Rack::Cache do
# add never-expire headers to responses that have a cache breaking slug
import 'rack/cache/config/busters'
set :metastore, "file:cache/meta"
set :entitystore, "file:cache/body"
before {
@env['PATH_INFO'].sub! /\/$/
}
get '/foo' do
...
end
@rtomayko
rtomayko / gist:24342
Created November 13, 2008 01:54
lines.svg
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect width="300" height="100" style="fill:rgb(255,255,255);stroke-width:0.5;stroke:rgb(0,0,0)"/>
</svg>
require 'time'
start = Time.now
10000.times do
require 'time'
end
duration = Time.now - start
printf "require: %f\n", duration
start = Time.now