Skip to content

Instantly share code, notes, and snippets.

@dagobar
dagobar / snitch_gateway.rb
Created July 16, 2013 15:06
dead mans snitch stats
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
@dagobar
dagobar / item_creation_with_responders.rb
Created November 28, 2012 11:56
A quick spike to play around with responder objects in controllers
require 'delegate'
class Object
def blank?
respond_to?(:empty?) ? empty? : !self
end
end
module Subscriberable
# poor man's subscription module
def subscribe(interested_listener)
@dagobar
dagobar / zipper.rb
Created September 15, 2011 12:59
Permutation problem
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
@dagobar
dagobar / gist:1154257
Created August 18, 2011 15:08
Current user in model
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
@dagobar
dagobar / protect.rb
Created August 12, 2011 13:53
Can't get current user
###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)