Skip to content

Instantly share code, notes, and snippets.

View djanowski's full-sized avatar

Damian Janowski djanowski

View GitHub Profile
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:
class Report
def update_tipifications(tipifications)
self.tipifications = tipifications
analizar!
save!
end
end
class ReportsController
def save
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
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
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
# 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
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(/\]$/, "")
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
require "redis"
Redis.current.flushall
def tokenize(string)
(0..(string.size - 3)).map do |i|
string[i, 3]
end
end
// 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) {