Skip to content

Instantly share code, notes, and snippets.

View mech's full-sized avatar
🏠
Working from home

mech mech

🏠
Working from home
  • Career Pacific / Jobline
  • Singapore, Tampines
View GitHub Profile
@mech
mech / god.rb
Created July 27, 2009 17:10 — forked from defunkt/god.rb
rails_root = "/data/github/current"
20.times do |num|
God.watch do |w|
w.name = "dj-#{num}"
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{rails_root}/Rakefile production jobs:work"
w.uid = 'git'
=== Epic Snow Leopard Upgrayyyyd Guide ===
Son, you’re now living in the land of 64-bit systems.
That means that some of your 32-bit shit is now broken.
Not all is lost.
== Fixing MySQL weirdness
@mech
mech / nginx.conf
Created January 1, 2010 02:32 — forked from crigor/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /opt/local/lib/passenger;
passenger_ruby /opt/local/bin/ruby;
def update_counter(record, *names)
updates = names.each_with_object({}) do |name, memo|
counter = "#{name}_count"
diff = record.send(name).count - record.send(counter)
memo[counter] = diff unless diff.zero?
end
record.class.update_counters(record.id, updates) if updates.any?
end
Community.paginated_each(:per_page => 100) do |record|
#!/usr/bin/env ruby
# Written by Kieran P
# http://github.com/KieranP
# http://twitter.com/k776
# http://k776.tumblr.com
#
# Feel free to fork and modify.
# If you do, send me a message on
# Github details changes and I'll
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts.all_cached # Retrive only at once by every 5 minutes
expires_in 5.minutes, :private => false, :public => true
end
end
# app/models/post.rb
Class Post
@mech
mech / gist:292410
Created February 2, 2010 05:31 — forked from hosiawak/gist:208774
require 'geoip'
module Rack
# Rack::GeoIPCountry uses the geoip gem and the GeoIP database to lookup the country of a request by its IP address
# The database can be downloaded from:
# http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
#
# Usage:
# use Rack::GeoIPCountry, :db => "path/to/GeoIP.dat"
#
env_vars = "RAILS_ENV=production PATH=/sb/thehierarchy/ruby/bin:/sb/thehierarchye/nginx/sbin:$PATH RUBY_HEAP_MIN_SLOTS=500000 RUBY_HEAP_SLOTS_INCREMENT=250000 RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 RUBY_GC_MALLOC_LIMIT=50000000"
RAILS_ROOT = "/var/www/apps/thehierarchy/current/"
Bluepill.application("thehierarchy") do |app|
app.process("scheduled_notifications") do |process|
process.group = "thehierarchy"
process.pid_file = File.join(RAILS_ROOT, "tmp", "pids", "scheduled_notifications")
process.daemonize = true
process.start_command = "/usr/bin/env #{env_vars} rake --rakefile=#{RAILS_ROOT}/Rakefile app_name:scheduled_notifications"
require 'rubygems'
require 'sinatra'
require 'datamapper'
require 'dm-paperclip'
require 'haml'
require 'fileutils'
APP_ROOT = File.expand_path(File.dirname(__FILE__))
DataMapper::setup(:default, "sqlite3://#{APP_ROOT}/db.sqlite3")
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)