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
@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 -->
@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
#!/bin/sh
# generate sinatra app
mkdir -p $1/views $1/public
cat <<RUBY > $1/app.rb
#!/usr/bin/env ruby
require 'sinatra'
set :views, File.dirname(__FILE__) + '/views'
class App1 < Sinatra::Base
set :views, "/path/to/views"
set :public, "/path/to/static/files"
def strong(text)
"<strong>#{text}</strong>"
end
get '/' do
strong "Hello World"