Skip to content

Instantly share code, notes, and snippets.

# Redis
%w{6379}.each do |port|
God.watch do |w|
w.name = "redis"
w.interval = 30.seconds
w.start = "/etc/init.d/redis start"
w.stop = "/etc/init.d/redis stop"
w.restart = "/etc/init.d/redis restart"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
@elvuel
elvuel / nginx.puma.conf
Created October 30, 2012 06:34 — forked from dariocravero/nginx.puma.conf
Nginx + Puma
upstream myapp {
server unix:///myapp/tmp/puma.sock;
}
server {
listen 80;
server_name myapp.com;
# ~2 seconds is often enough for most folks to parse HTML/CSS and
# retrieve needed images/icons/frames, connections are cheap in
@elvuel
elvuel / README.md
Created October 30, 2012 06:34 — forked from pzol/README.md
RVM + Puma + Ubuntu

Running Puma on Nginx

I use the latest Puma v1.4.0 from rubygems.

Make sure you have nginx installed with these options:

>/opt/nginx/sbin/nginx -V
nginx version: nginx/1.0.15

built by gcc 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

@elvuel
elvuel / setup.md
Created October 8, 2012 06:35 — forked from leesmith/setup.md
Ruby on Rails development setup on Ubuntu 12.04 (vim, git, rbenv)

Ruby on Rails development setup on Ubuntu 12.04

System update

# change mirror to ubuntu.osuosl.org first
sudo apt-get update

Install common libraries

sudo apt-get install build-essential libreadline-dev libssl-dev zlib1g-dev libxml2-dev libxslt-dev

@elvuel
elvuel / 0.rb
Created October 8, 2012 04:02 — forked from jccarbonfive/0.rb
enum = Enumerator.new do |yielder|
yielder << "a"
yielder << "b"
yielder << "c"
end
enum.next # "a"
enum.next # "b"
enum.next # "c"
enum.next # StopIteration: iteration reached an end
@elvuel
elvuel / mocha-minitest-integration-options.md
Created September 20, 2012 10:33 — forked from floehopper/mocha-minitest-integration-options.md
Mocha/MiniTest integration options

Mocha/MiniTest integration

I think that the approach @tenderlove has suggested to avoid monkey-patching MiniTest (and the way MiniTest works) means that to use Mocha with MiniTest, you would either need to include the Mocha integration module into every test case, or define your own test case class inheriting from MiniTest::Unit::TestCase.

This works well for Rails (i.e. ActiveSupport), because it already defines a new test case class (ActiveSupport::TestCase) which is a suitable place to include the Mocha integration module.

If we were to go down this route, in non-Rails Ruby projects you'd need to do one of the following...

Option A

@elvuel
elvuel / redis_pubsub_demo.rb
Created September 11, 2012 09:03 — forked from tobym/redis_pubsub_demo.rb
Redis PubSub demo with EventMachine (chat service)
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# - a browser with WebSocket support
#
# Usage:
# ruby redis_pubsub_demo.rb
#
@elvuel
elvuel / ldap_admin.rb
Created August 6, 2012 08:55 — forked from rykr30/ldap_admin.rb
Simple Sinatra based LDAP admin tool
require 'rubygems'
require 'sinatra'
require 'net-ldap'
require 'digest/sha1'
require 'base64'
require 'haml'
LDAP_HOST = 'localhost'
ADMIN_DN = 'cn=admin,dc=company,dc=com'
@elvuel
elvuel / directory_controller.rb
Created August 6, 2012 08:48 — forked from DanCoughlin/directory_controller.rb
Here is the main ldap library and then the directory controller where these are used and the user model that exposes the ldap functionality
# returns true if the user exists and false otherwise
def user
render :json => User.attributes(params[:uid])
end
def user_attribute
if params[:attribute] == "groups"
res = User.groups(params[:uid])
else
res = User.attributes(params[:uid], params[:attribute])
@elvuel
elvuel / ldap_bind.rb
Created August 6, 2012 07:48 — forked from seven1m/ldap_bind.rb
net/ldap example code for Active Directory
require 'net/ldap'
# how to "bind" to your ldap/ad server...
LDAP_HOST = 'server'
LDAP_PORT = 389
LDAP_USERNAME = 'cn=Username;cn=Users;dc=domain;dc=com'
LDAP_PASSWORD = 'your user password'
LDAP_BASE = 'dc=domain;dc=com'
# replace "domain" and "com" above with your AD domain