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
def ask_password(message)
HighLine.new.ask(message) do |q|
q.echo = false
end
end
@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"
@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 / 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 / Replaceable.rb
Created October 3, 2011 09:51
Replaceable module for ruby String class
module Replaceable
def self.include_me!(_class)
_class.class_eval do
include Replaceable
end
end
def replace_values!(locals)
locals.each{ |key, val| self.gsub!("%%#{key.to_s.upcase}%%", val) }
self
@ritxi
ritxi / gist:1647628
Created January 20, 2012 14:37
git color
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
branch_color ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
@ritxi
ritxi / gist:2311731
Created April 5, 2012 14:56 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
require 'test_helper'
class DecrypterTest < Test::Unit::TestCase
include InformationCard
def test_should_decrypt_encrypted_xml_token_into_saml_token
decrypter = Decrypter.new(
load_encrypted_information_card('wuaki.xml'),certificates_directory,
'/O=testinformationcardruby.com/CN=*.wuaki.tv')
puts decrypter.decrypt
@ritxi
ritxi / 0-readme.md
Created December 6, 2012 19:39 — forked from burke/0-readme.md
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@ritxi
ritxi / _steps.html.haml
Last active August 29, 2015 13:56
Wizzard with bootstrap
.wizard
= step(1, 'Inscripció')
= step(2, 'Verificació')
= step(3, 'Pagament')
= step(4, 'Final')