Skip to content

Instantly share code, notes, and snippets.

# Proposal of implementation Django-like generic views in rack and rango compatible way
# It must play well with:
# 1) Rack apps
# 2) Rango controllers
# NOTE: if you don't know what generic views are, take a look at
# http://docs.djangoproject.com/en/dev/ref/generic-views/
# generic view
def render_template(env)
gem "hpricot", "0.8.1"
require "hpricot"
html = <<-HTML
<div class="info">
<p><strong>Job description</strong></p> <!-- elements[0] -->
<p id="ctl00_MainContent_CD_CD_Drop_DescHTML"> <!-- elements[1] -->
<p></p>
<p></p>
<p>Location: Barrs Court Specialist (SEN) School, Barrs Court Road, Hereford, HR1 1EQ</p>
** has_many_polymorphs: autoload hook invoked
** has_many_polymorphs: preloading parent model Tag
** has_many_polymorphs: associating Tag.taggables
Tagging Columns (0.027593) SHOW FIELDS FROM `taggings`
Vacancy Columns (0.001997) SHOW FIELDS FROM `vacancies`
** has_many_polymorphs: preloading parent model Tagging
Cache hit: route_filters/all ({:expires_in=>300 seconds})
RouteFilter Columns (0.001286) SHOW FIELDS FROM `route_filters`
Cache hit: route_filters/all ({:expires_in=>300 seconds})
User Columns (0.001988) SHOW FIELDS FROM `users`
module GetNestedItemMixin
# Simplier syntax for code such as params[:post] && params[:post][:title]
#
# @author Jakub Stastny aka Botanicus
# @param [Object] First argument is the key of the hash, the second one the key of the inner hash selected by the first key etc.
# @return [Object, nil] The value of the most inner hash if found or nil.
# @raise [ArgumentError] If you don't specify keys.
#
# @example
# {a: {b: 1}}.get(:a, :b) # => 1
#!script/runner
# jsou to tři hlavní skupiny:
#
# 6.směrnice
#
# nové cases - ty je potřeba navázat přes smartlink na šestou směrnici - je tam sloupec s příslušným article
# staré cases - totéž
#
# u všech smartlinků bych dal implicitně 5 hvězdiček
# ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-darwin9.6.0]
user system total real
by_define_method 0.680000 0.000000 0.680000 ( 0.700586)
by_explicit_definition 0.560000 0.010000 0.570000 ( 0.581977)
by_eval 0.550000 0.000000 0.550000 ( 0.553484)
by_class_eval 0.540000 0.010000 0.550000 ( 0.561800)
by_class_eval_block 0.540000 0.000000 0.540000 ( 0.548041)
by_module_eval 0.550000 0.010000 0.560000 ( 0.560635)
by_module_eval_block 0.520000 0.000000 0.520000 ( 0.539168)
require "rubygems"
require "rbench"
def omg_slow
return 1
end
def omg_fast
1
end
require "rbench"
RBench.run(1_000_000) do
column :one, :title => "String"
column :two, :title => "String using String.new"
column :three, :title => "Array"
column :four, :title => "Array using Array.new"
column :five, :title => "Hash"
column :six, :title => "Hash using Hash.new"
namespace :sites do
# use for sites deployment
# Usage:
# cap sites:deploy
task :deploy do
run "cd #{shared_path}/sites"
run "(test -f sites.lock) && (echo 'Sites are locked:' && cat sites.lock) || git update"
end
# Run just on first deploy to given server
def my_method
puts whatever
rescue Exception => e
puts "Exception #{e.message} occured!"
end
my_method
def my_method2
puts whatever