Skip to content

Instantly share code, notes, and snippets.

View arikfr's full-sized avatar

Arik Fraimovich arikfr

View GitHub Profile
# an example Monit configuration file for collectiveidea's fork of delayed_job.
# See: http://stackoverflow.com/questions/1226302/how-to-monitor-delayedjob-with-monit/1285611
#
# To use:
# 1. replace {app_name} and {environment} as appropriate
# 2. copy to your repository under config/delayed_job.monitrc
# 3. add this to your /etc/monit/monitrc:
#
# include /var/www/apps/{app_name}/current/config/*.monitrc
# 4. reload monit when you deploy to pick up any changes to your monitrc files: sudo monit reload
@trydionel
trydionel / backbone.rails.js
Created November 28, 2010 16:47
Makes Backbone.js play nicely with default Rails setup
//
// Backbone.Rails.js
//
// Makes Backbone.js play nicely with the default Rails setup, i.e.,
// no need to set
// ActiveRecord::Base.include_root_in_json = false
// and build all of your models directly from `params` rather than
// `params[:model]`.
//
// Load this file after backbone.js and before your application JS.
@amw
amw / ar_patch.rb
Created January 19, 2011 19:19
A patch that allows lambda arguments to default_scope in rails ~> 3.0.0
module ActiveRecord
class Base
class << self
def default_scope(options = {})
reset_scoped_methods
default_scoping = self.default_scoping.dup
previous = default_scoping.pop
if previous.respond_to?(:call) or options.respond_to?(:call)
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@FSX
FSX / async_psycopg2.py
Created March 8, 2011 22:11
A module for asynchronous PostgreSQL queries in Tornado.
#!/usr/bin/env python
__author__ = 'Frank Smit <frank@61924.nl>'
__version__ = '0.1.0'
import functools
import psycopg2
from tornado.ioloop import IOLoop, PeriodicCallback
@apalmblad
apalmblad / fast-require-ruby-19.2-p180
Created May 30, 2011 20:46
fast require, ruby 1.9.2-180
diff --git a/array.c b/array.c
index b1616c5..16326fc 100644
--- a/array.c
+++ b/array.c
@@ -302,7 +302,7 @@ ary_alloc(VALUE klass)
return (VALUE)ary;
}
-static VALUE
+VALUE
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:29
Focus on specific specs in RSpec
# add this to your spec helper
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
# and then use the :focus tag in your specs
it "does something awesome", :focus do
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:37
Use RSpec tags to add behavior around specs.
# Add this to your spec_helper.rb
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].downcase.gsub(/\W+/, "_").split("_", 2).join("/")
VCR.use_cassette(name, :record => :new_episodes) do
example.call
end
end
end
@SupermanScott
SupermanScott / gist:1658409
Created January 22, 2012 19:35
Tornado Server-Sent Event handler
class SSEHandler(tornado.web.RequestHandler):
def initialize(self):
self.set_header('Content-Type', 'text/event-stream')
self.set_header('Cache-Control', 'no-cache')
def emit(self, data, event=None):
"""
Actually emits the data to the waiting JS
"""
response = u''