Skip to content

Instantly share code, notes, and snippets.

View tbuehlmann's full-sized avatar

Tobias Bühlmann tbuehlmann

View GitHub Profile
@tbuehlmann
tbuehlmann / application.rb
Created June 26, 2009 14:11
Sinatra Template
%w{rubygems sinatra haml}.each {|r| require r}
configure do
set :views, "#{File.dirname(__FILE__)}/views"
end
get '/' do
haml "Hello World!"
end
@tbuehlmann
tbuehlmann / upload.rb
Created August 18, 2009 11:17
File upload with Sinatra
require 'rubygems'
require 'sinatra'
get '/' do
@files = Dir['public/*'].map {|f| File.basename(f) }
erb :index
end
post '/upload' do
filename = params[:file][:filename]
@tbuehlmann
tbuehlmann / config.ru
Created October 4, 2009 16:11
CSS Test
require 'index'
run Sinatra::Application
@tbuehlmann
tbuehlmann / config.ru
Created October 27, 2009 18:16
AJAXy Sieve of Eratosthenes with Sinatra
require 'index'
run Sinatra::Application
@tbuehlmann
tbuehlmann / gist:249242
Created December 4, 2009 18:46
clarity error (0.9.5)
$ clarity --username=admin --password=secret --port=8080 logs/
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- clarity/parsers/time_parser (LoadError)
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/clarity-0.9.5/lib/clarity.rb:10
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /usr/local/lib/ruby/gems/1.8/gems/clarity-0.9.5/bin/clarity:7
from /usr/local/bin/clarity:19:in `load'
from /usr/local/bin/clarity:19
%a{:href => 'http://github.com/rodrigo3n'}<
%img{:style => 'position: absolute; top: 0; right: 0; border: 0;', :src => 'http://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png', :alt => 'Fork me on GitHub'}
text = 'I like cats'
['cat', 'dog', 'mouse'].any? { |word| text =~ /#{Regexp.escape(word)}/ } # => true
# provides a slick way to add classes inside haml attribute collections
#
# examples:
# %div{add_class("current")}
# #=> adds the "current" class to the div
#
# %div{add_class("current", :if => current?)}
# #=> adds the "current" class to the div if current? method
#
# %div{add_class("highlight", :unless => logged_in?)}
@tbuehlmann
tbuehlmann / README
Created April 29, 2010 19:19
Installing Ruby 1.9.1-p378 on Ubuntu 10.04
sudo apt-get install build-essential zlib1g zlib1g-dev zlibc libruby1.9 libxml2 libxml2-dev libxslt-dev
sudo apt-get build-dep ruby1.9
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p376.tar.gz
untar it, open ext/Setup and uncomment zlib
./configure
make
sudo make install
@contact = Contact.find params[:id]
@contact.attributes = params[:contact]
if params[:is_supplier] == '1'
@contact.type = 'supplier'
elsif params[:is_supplier] == '0'
@contact.type = 'customer'
end
if @contact.save