This file contains hidden or 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 'mechanize' | |
module Snitcher | |
class SnitchGateway | |
def initialize(login, password, snitch_id) | |
@login = login | |
@password = password | |
@snitch_url = "https://deadmanssnitch.com/snitches/#{snitch_id}" | |
end |
This file contains hidden or 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 'delegate' | |
class Object | |
def blank? | |
respond_to?(:empty?) ? empty? : !self | |
end | |
end | |
module Subscriberable | |
# poor man's subscription module | |
def subscribe(interested_listener) |
This file contains hidden or 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
array1 = [[:foo,:bar],[:zux]] # => [:foo,:zux] , [:bar,:zux] | |
# array.first.zip(array.last.cycle) ??? | |
array2 = [[:foo,:bar],[:baz,:zux]] # => [[:foo,:baz],[:foo,:zux],[:bar,:baz],[:bar,:zux]] | |
r = array2.reduce do |a, b| | |
b.flat_map do |bi| | |
a.map do |ai| | |
[*ai, bi] | |
end |
This file contains hidden or 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 Protect | |
extend ActiveSupport::Concern | |
included do | |
if self < ActiveRecord::Base | |
self.send(:after_initialize) {init} | |
elsif self < ActionController::Base | |
self.send(:prepend_before_filter) { self.init(current_user.keys) } | |
end | |
end | |
This file contains hidden or 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
###Watered down version, how do I get current_user in the initialize method? | |
module Protect | |
extend ActiveSupport::Concern | |
module ClassMethods | |
#stuff | |
end | |
module InstanceMethods | |
def initialize (*args, &block) |