Skip to content

Instantly share code, notes, and snippets.

View shinzui's full-sized avatar
👨‍💻

Nadeem Bitar shinzui

👨‍💻
  • Los Angeles / San Francisco
  • X @shinzui
View GitHub Profile
@shinzui
shinzui / gist:217690
Created October 24, 2009 18:58 — forked from dhh/gist:45076
Subdomain routing in rails
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName example.com
# ServerAlias *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
# 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
if RAILS_ENV != 'development'
require 'cache_money'
config = YAML.load(IO.read(File.join(RAILS_ROOT, "config", "memcached.yml")))[RAILS_ENV]
$memcache = MemCache.new(config)
$memcache.servers = config['servers']
$local = Cash::Local.new($memcache)
$lock = Cash::Lock.new($memcache)
$cache = Cash::Transactional.new($local, $lock)
@shinzui
shinzui / gist:240317
Created November 21, 2009 22:40 — forked from defunkt/gist:240307
$ cat test.rb
class Person
end
Person.new
$ cat test.rb | irb
>> class Person
>> end
=> nil
>>
@shinzui
shinzui / random_password.rb
Created December 1, 2009 01:59
Random Password
def random_password(size = 8)
chars = (('a'..'z').to_a + ('0'..'9').to_a) - %w(i o 0 1 l 0)
(1..size).collect{ chars[rand(chars.size)] }.join
end
@shinzui
shinzui / check_for_memcached.rb
Created December 1, 2009 07:58 — forked from subelsky/check_for_memcached.rb
Enable memcache store in dev if memcached is running
begin
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } }
config.cache_store = :mem_cache_store, %w(localhost:11211), { :namespace => 'OI', :timeout => 60 }
$stderr.puts "Using memcached on localhost:11211"
rescue StandardError
config.cache_store = nil
$stderr.puts "memcached not running, caching to memory"
end
@shinzui
shinzui / connection_fix.rb
Created December 6, 2009 06:18 — forked from defunkt/connection_fix.rb
MySQL automatic reconnect
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
@shinzui
shinzui / url_dsl.rb
Created December 16, 2009 05:04 — forked from defunkt/url_dsl.rb
URL DSL
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
HANDY ONE-LINERS FOR RUBY November 16, 2005
compiled by David P Thomas <davidpthomas@gmail.com> version 1.0
Latest version of this file can be found at:
http://www.fepus.net/ruby1line.txt
Last Updated: Wed Nov 16 08:35:02 CST 2005
FILE SPACING: