Skip to content

Instantly share code, notes, and snippets.

View ritxi's full-sized avatar
🎗️

Ricard Forniol ritxi

🎗️
  • Sage
  • Sabadell, República Catalana
View GitHub Profile
@ritxi
ritxi / prova.rb
Created July 28, 2011 18:52
Hpricot example
require 'hpricot'
require 'open-uri'
doc = open("http://qwantz.com/") { |f| Hpricot(f) }
doc.search("//body").count
@ritxi
ritxi / caching_dsl
Created May 20, 2011 09:54
counter cache dsl
cache_for :invitiations do |invitation|
invitation(:new) do |action|
action.increase(:create)
action.decrease(:update, :not => :to_pending?)
end
invitation(:accepted) do |action|
action.increase(:to_accepted?)
action.decrease(:update, :not => :to_accepted?)
end
invitation(:rejected) do |action|
@ritxi
ritxi / embed.rb
Created February 25, 2011 19:37
transform a youtube url into a embed youtube video
def embed_url(string)
(match = /^(http|https)\:\/\/www\.youtube\.com\/watch\?v\=(\w*)(\&(.*))?$/i.match(string)) ? "http://www.youtube.com/e/#{match[2]}" : nil
end
puts embed_url( "http://www.youtube.com/watch?v=ONvTNAG2e9c&feature=related") == "http://www.youtube.com/e/ONvTNAG2e9c"
puts embed_url("http://www.youtube.com/watch?v=ONvTNAG2e9c") == "http://www.youtube.com/e/ONvTNAG2e9c"
puts embed_url("http://www.hola.com/watch?v=ONvTNAG2e9c") == "http://www.hola.com/e/ONvTNAG2e9c"
def ask_password(message)
HighLine.new.ask(message) do |q|
q.echo = false
end
end