Skip to content

Instantly share code, notes, and snippets.

@arches
arches / instance_block.rb
Last active February 17, 2016 17:56
Syntactic sugar for simple filtering. A halfway point between posts.select(&:published) and posts.select{|post| post.comments.any?}
# before - each object in the enumerable is passed to the block
posts.select { |post| post.comments.any? }
class Array
def select(&blk)
if blk.arity == 0
super { |obj| obj.instance_exec &blk }
else
super
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@arches
arches / Procfile
Last active February 16, 2021 10:44
A little hack to restart Heroku web dynos when they hit 1000MB of memory
monitor: bundle exec ruby monitor.rb
@jonkgrimes
jonkgrimes / unicorn.rb
Last active November 18, 2016 18:44
Unicorn.rb for keen.io configuration
worker_processes 3 # amount of unicorn workers to spin up
timeout 30 # restarts workers that hang for 30 seconds
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server,worker|
defined?(ActiveRecord::Base) and