Skip to content

Instantly share code, notes, and snippets.

View jackdempsey's full-sized avatar

jack dempsey jackdempsey

View GitHub Profile
@jackdempsey
jackdempsey / gist:3200090
Created July 29, 2012 16:34
Chatting about rails-api
I'm wondering what speed benefits using rails-api gives you over the normal rails stack. Conceptually it makes sense that removing unneeded pieces will help, but most of the default rails middleware is still in place, so I'm wondering if the boost is actually noticeable.
Removing those pieces does restrict your ability to use things like active_admin to manage your data, so I'd only go with the slimmer rails-api style project if the improvements are noticeable.
git rm `git status | grep deleted | cut -f2 -d: | xargs`
= form_for @list do |f|
no routes matches /lists
= form_for @list, url: (@list.new_record? ? lists.lists_path : lists.list_path(@list) do |f|
@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]