This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'production' | |
worker_processes (rails_env == 'production' ? 5 : 3) | |
preload_app true | |
timeout 30 | |
listen 20000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Goes in /etc/init/<name>.conf | |
description "Unicorn w/Rails" | |
start on runlevel [2345] | |
stop on runlevel [016] | |
setuid <uid> | |
setgid <gid> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'ffi-rzmq' | |
require 'json' | |
class ZMQLogger | |
attr_reader :context | |
def initialize | |
@context = ZMQ::Context.new | |
@logger = @context.socket(ZMQ::PAIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
It seems I can't make a secret gist public, so here's the URL: | |
https://gist.github.com/toretore/35eb74a2cac3f214fd4b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; }')}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contract < ActiveRecord::Base | |
has_paper_trail | |
acts_as_restful_list | |
CHANGE_FIELDS_MAP = { | |
'contract_status_id' => { | |
:association => 'contract_status' | |
:field => 'name' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PullSource | |
def self.implementations | |
@implementations ||= {} | |
end | |
def self.register(name) | |
implementations[name] << self | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |