Skip to content

Instantly share code, notes, and snippets.

View porras's full-sized avatar

Sergio Gil Pérez de la Manga porras

View GitHub Profile
run "rm public/index.html"
file '.gitignore', <<-IGNORE
log/*.log
tmp/**/*
.DS_Store
doc/api
doc/app
db/*.sqlite3
IGNORE
run "touch log/.gitignore"
class Wadus < ActiveRecord::Base
named_scope :limited, lambda {|n| { :limit => n }}
named_scope :low_id, :conditions => "id < 500"
end
Wadus.low_id.limited(5)
# SELECT * FROM "wadus" WHERE (id < 500) LIMIT 5
input = "foo bar wadus wadus"
File.open("path/to/input.txt", "w") do |f|
f.puts input
end
system("path/to/wadus.exe")
output = File.read("path/to/output.txt")
ActionController::Routing::Routes.draw do |map|
map.root :controller => 'posts'
end
$ rake routes
root / {:controller=>"posts", :action=>"index"}
require 'yaml'
def yacss(data)
YAML.load(data).map do |item|
item.map do |selector, properties|
"#{selector} {\n" +
properties.map do |property, value|
" #{property}: #{value};\n"
end.join +
"}\n"
Toronto List
============
Clothes
-------
* 10 camisetas
* 10 calzoncillos
* 10 pares de calcetines
* 1 camisa
# paste into .irbrc
require 'benchmark'
def time(&block)
result = nil
Benchmark.bm do |bm|
bm.report { result = yield }
end
result
user system total real
slow 9.350000 0.140000 9.490000 ( 11.120732)
fast 0.780000 0.010000 0.790000 ( 0.912680)
// ==UserScript==
// @name More Diversion
// @namespace http://github.com/porras
// @description Fixes some Diversion bugs client-side ;-)
// @include http://diversion.r09.railsrumble.com/*
// ==/UserScript==
$ = unsafeWindow.jQuery
$(document).ready(function() {
def calculate_range_start_of_months
#Catacrocker obscurism
[current = range.begin.beginning_of_month].tap { |result| result << current while (current += 1.month) <= range.end }
end