Skip to content

Instantly share code, notes, and snippets.

View jackdempsey's full-sized avatar

jack dempsey jackdempsey

View GitHub Profile
@jackdempsey
jackdempsey / gist:2656858
Created May 11, 2012 00:59
Resolvers gem
1 module Resolvers
2 autoload :MobileFallbackResolver, 'resolvers/mobile_fallback_resolver'
3
4 #ActiveSupport.on_load(:action_controller) do
5 #append_view_path(MobileFallbackResolver.new('app/views'))
6 #end
7
8 # class Railtie < ::Rails::Railtie
9 # initializer 'resolvers.mobile_fallback_resolver' do |app|
10 # ActiveSupport.on_load(:action_controller) do
constraint = lambda { |request| request.env["warden"].authenticate? and request.env['warden'].user.admin? }
constraints constraint do
mount Sidekiq::Web => '/sidekiq'
end
@jackdempsey
jackdempsey / gist:2409371
Created April 17, 2012 22:02
easily set sidekiq to directly send emails rather than delaying them
module Sidekiq
module Extensions
class Proxy
def method_missing(name, *args)
@target.send(name, *args).deliver
end
end
end
end
@jackdempsey
jackdempsey / neural_network.coffee
Created April 11, 2012 07:12 — forked from bryanbibat/neural_network.coffee
Basic feedforward neural network that's coded by every kid who took an AI class in college. Test case for XOR training included.
class Synapse
constructor: (@sourceNeuron, @destNeuron) ->
@prevWeight = @weight = (Math.random() * 2.0) - 1.0
class Neuron
learningRate: 1.0
momentum: 0.3
constructor: ->
@synapsesIn = []
remaining: function() {
return this.filterProperty('isDone', false).get('length');
}.property('@each.isDone'),
(defn divisible-by-3-or-5? [num] (or (== (mod num 3) 0)(== (mod num 5) 0)))
#'user/divisible-by-3-or-5?
user=> (take-while divisible-by-3-or-5? [7 9 13 5 8 3 1])
()
user=> (take-while odd? [7 9 13 5 8 3 1])
(7 9 13 5)
ree-1.8.7-2011.03 :001 > messages = []
=> []
ree-1.8.7-2011.03 :002 > messages << {:a => 1, :b => 2}
=> [{:b=>2, :a=>1}]
ree-1.8.7-2011.03 :003 > messages << {:a => 3, :b => 4}
=> [{:b=>2, :a=>1}, {:b=>4, :a=>3}]
ree-1.8.7-2011.03 :004 > messages.map do |m|
ree-1.8.7-2011.03 :005 > m[:a] = 5
ree-1.8.7-2011.03 :006?> end
=> [5, 5]
Loading development environment (Rails 3.1.0)
ree-1.8.7-2011.03 :001 > I18n.locale
=> :"en-US"
ree-1.8.7-2011.03 :002 > exit
~/project > git checkout master
Previous HEAD position was x314a19... bundle in activeadmin
Switched to branch 'master'
Loading development environment (Rails 3.1.0)
class Subscription
belongs_to :user
belongs_to :magazine
validates :user_id, :uniqueness => {:scope => :magazine_id}
end
class Foo < ActiveRecord::Base
include Models::Scopes::Order
default_scope recently_updated # didn't realize you could do this
end