Skip to content

Instantly share code, notes, and snippets.

rails_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'production'
worker_processes (rails_env == 'production' ? 5 : 3)
preload_app true
timeout 30
listen 20000
#Goes in /etc/init/<name>.conf
description "Unicorn w/Rails"
start on runlevel [2345]
stop on runlevel [016]
setuid <uid>
setgid <gid>
require 'ffi-rzmq'
require 'json'
class ZMQLogger
attr_reader :context
def initialize
@context = ZMQ::Context.new
@logger = @context.socket(ZMQ::PAIR)
@toretore
toretore / _etc_dbus-1_system.d_Upstart.conf
Last active December 15, 2015 00:28
Upstart config for running thin (or anything else, I guess) through rbenv Chances are your OS hasn't enables so-called user jobs by default and you'll have to edit the upstart config for this to work. I've included the upstart config file I've used. Upstart also won't run any user jobs by default because they won't hav been loaded into its syste…
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only the root user can own the Upstart name -->
<policy user="root">
<allow own="com.ubuntu.Upstart" />
</policy>
@toretore
toretore / gist:4749992
Created February 10, 2013 15:54
Mongrel2 handlers
It seems I can't make a secret gist public, so here's the URL:
https://gist.github.com/toretore/35eb74a2cac3f214fd4b
class JSFunction
def initialize(f)
@f = f
end
def to_json(*a, &b)
@f
end
end
puts JSON.generate({:foo => 'bar', :aFunction => JSFunction.new('function(){ return "foo"; }')})
@toretore
toretore / gist:1922637
Created February 27, 2012 09:02
something like this in the contract model
class Contract < ActiveRecord::Base
has_paper_trail
acts_as_restful_list
CHANGE_FIELDS_MAP = {
'contract_status_id' => {
:association => 'contract_status'
:field => 'name'
}
@toretore
toretore / explicit.rb
Created November 15, 2011 10:03 — forked from mikebaldry/gist:1366593
find subclasses
class PullSource
def self.implementations
@implementations ||= {}
end
def self.register(name)
implementations[name] << self
end
@toretore
toretore / README
Created May 4, 2011 08:08
Rails authentication
User authentication with Rails
This is all you need to have fully working and secure authentication in Rails.
Why use this instead of <bloated auth framework>? Well, there are a number of
reasons, but I guess you'll just have to go through a few apps where you
learn the hard way why the idea of a "fully featured" authentication
framework that doesn't get on your nerves is a mirage.
Don't simply copy and paste this without understanding everything it does. It's
# Returns a set of hidden fields for params passed in the query string such that they are passed
# along with the form. Mostly for use with GET forms like search/filtering where you want to retain
# other state while adding another (<existing params>&q=pr0n)
#
# Options:
#
# :skip - An array of keys to leave out - Only works for first-level keys, i.e. not 'bar' in foo[bar]=baz
def hidden_fields_from_params(opts={})
#Use CGI.parse to get "raw" parameters that haven't been converted into arrays
#and hashes yet. This means it only has to concern itself with the one dimension