This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def with_host(host) | |
previous_host = Rack::Test::DEFAULT_HOST.dup | |
Rack::Test::DEFAULT_HOST.replace host | |
yield | |
ensure | |
Rack::Test::DEFAULT_HOST.replace previous_host | |
end | |
# Usage: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Report | |
def update_tipifications(tipifications) | |
self.tipifications = tipifications | |
analizar! | |
save! | |
end | |
end | |
class ReportsController | |
def save |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "uri/generic" | |
module URI | |
class Redis < Generic | |
DEFAULT_PORT = 6379 | |
COMPONENT = [:scheme, :password, :host, :port, :db].freeze | |
def db | |
path[1..-1].to_i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Regarding databases in Redis | |
============================ | |
The question on named databases and requests for more database-aware | |
features is a recurrent issue in the Redis community. Salvatore has | |
explained why using databases is in most cases a bad idea, and thus | |
expressed that he won't add more features to it. | |
> I understand how this can be useful, but unfortunately I consider | |
> Redis multiple database errors my worst decision in Redis design at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "active_record" | |
module HasManyPreventDestroy | |
def has_many(association, options = {}, &extension) | |
before_destroy { send(association).empty? } if options.delete(:prevent_destroy) | |
super(association, options, &extension) | |
end | |
end | |
class Foo < ActiveRecord::Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Removing old Rubies in preparation for RVM | |
/usr/bin/gem list | awk '{ print $1 }' | xargs /usr/bin/gem uninstall -a --install-dir=/Library/Ruby/Gems/1.8 --bindir=/usr/bin | |
/usr/bin/gem list | awk '{ print $1 }' | xargs /usr/bin/gem uninstall -a --install-dir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 --bindir=/usr/bin | |
/opt/local/bin/gem list | awk '{ print $1 }' | xargs /opt/local/bin/gem uninstall -a | |
for file in $(find /usr/bin -type f); do (head -n1 $file | grep '^#.*ruby' > /dev/null) && echo $file && rm $file; done | |
port installed | ack '^(j?ruby|rb\-)' | awk '{ print $1, $2 }' | xargs port uninstall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
module JQuery | |
class Selector < BasicObject | |
def initialize(string) | |
@value = "jQuery(#{string.to_json})" | |
end | |
def method_missing(name, *args) | |
arguments = args.to_json.sub(/^\[/, "").sub(/\]$/, "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def ===(other) | |
return false if size != other.size | |
ours, theirs = each, other.each | |
loop { return false unless ours.next === theirs.next } | |
true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "redis" | |
Redis.current.flushall | |
def tokenize(string) | |
(0..(string.size - 3)).map do |i| | |
string[i, 3] | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allows to get browser-specific properties like column-count. | |
var cssPrefix = null; | |
if ($.browser.mozilla) cssPrefix = "moz"; | |
else if ($.browser.webkit) cssPrefix = "webkit"; | |
else if ($.browser.opera) cssPrefix = "o"; | |
$.cssHooks["columnCount"] = { | |
get: function(element, computed) { |