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 "thread" | |
module Synchronization | |
class Proxy | |
instance_methods.each { |m| undef_method m unless m =~ /^__|extend/ } | |
def initialize(target) | |
@__target__ = target | |
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
truncate table events; | |
CREATE TABLE events(ref_id integer, event_type text, ts integer); | |
INSERT INTO events (ref_id, event_type, ts) VALUES (1, 'foo', 1), (1, 'bar', 1), (2, 'foo', 0), (3, 'foo', 0), (1, 'foo', 4), (3, 'foo', 7), (2, 'bar', 10); | |
select | |
ref_id, | |
event_type, | |
ts, | |
first_value(ts) over ( | |
partition by ref_id, event_type order by ts asc rows between 1 following and unbounded following |
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 Option | |
private def initialize(value) | |
@value = value | |
end | |
def self.Some(value) | |
new(value) | |
end | |
None = new(nil) |
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 List | |
attr_accessor :head, :tail | |
def initialize(head, tail) | |
self.head = head | |
self.tail = tail | |
freeze | |
end | |
def prepend(elem) |
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 TrueClass | |
def choose(if_true, if_false) | |
if_true | |
end | |
end | |
class FalseClass | |
def choose(if_true, if_false) | |
if_false | |
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
Calendar = Class.create({ | |
MONTHS : ["gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio", "agosto", "settembre", "ottobre", "novembre", "dicembre"], | |
DAYS : ["dom", "lun", "mar", "mer", "gio", "ven", "sab"], | |
MONTH_DAYS : [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], | |
year : null, | |
month : null, | |
specialDates : null, | |
initialize : function(_special) { |
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" | |
require "open-uri" | |
require "optparse" | |
require "fileutils" | |
require "cgi" | |
class FriendfeedExporter | |
attr_reader :all_entries | |
def initialize(options) |
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 ActiveSupport::TestCase | |
class << self | |
def context(name, &block) | |
_context_stack_.unshift name.gsub(/\s+/,'_') | |
define_callbacks :"setup_#{_current_context_}", :"teardown_#{_current_context_}" | |
class_eval(&block) | |
_context_stack_.pop | |
end | |
def test_with_context(name, &block) |
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
module Decorating | |
def decorate(meth_id, *modules) | |
alias_method("__#{meth_id}__", meth_id) | |
define_method(meth_id) do |*args| | |
result = send("__#{meth_id}__", *args) | |
modules.each { |m| result.extend(m) } | |
return result | |
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
require "digest/sha1" | |
module AuthenticationModel | |
def self.included(base) | |
base.send(:include, InstanceMethods) | |
base.send(:extend, ClassMethods) | |
base.send(:validates_presence_of, :email, :message => "L'indirizzo email è richiesto.") | |
base.send(:validates_presence_of, :password, :if => :password_required?, :message => "La password è richiesta.") | |
base.send(:validates_uniqueness_of, :email, :case_sensitive => false, :message => "Questo indirizzo email è già presente.") |
NewerOlder