Skip to content

Instantly share code, notes, and snippets.

View railsbob's full-sized avatar

Anup Narkhede railsbob

View GitHub Profile
namespace :delayed_job do
task :kill_stale_processes => :environment do
pid_list = IO::popen('ps aux|awk "{if (\$11 ~ \"delayed_job\") print \$2}"')
pids = pid_list.read.split(/\W+/)
pids.each do |pid|
%x[kill -9 #{pid}]
end
puts "Killed unresponsive delayed_job pids: #{pids.join(', ')}" if pids.any?
end
end
# Remove all files in a directory /backup/sql which are older than 7 days
find /backup/sql -mtime +168 -type f -name '*.sql' -exec rm {} \;
# We want the account namespace routes available only if subdomains are specified
constraints(:subdomain => /[A-Za-z0-9]/) do
namespace :account do
resources :users
end
end
# Which folder is eating up the space?
du -s * | sort -n
# To fix unicode character errors in mysql
# => Put this file in lib and require it in environment.rb
require 'mysql'
class Mysql::Result
def encode(value, encoding = "utf-8")
String === value ? value.force_encoding(encoding) : value
end
# Pretty commified numbers
module ApplicationHelper
def format_num(num, delim = ',')
number_with_precision(num, :precision => 2, :separator => '.', :delimiter => ',')
end
end
Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'saas'
s.version = '0.1'
s.description = 'A generic modular application.'
s.required_ruby_version = '>= 1.8.7'
s.author = 'Anup Narkhede'
s.require_path = 'lib'
end
gem 'saas', :require => 'saas', :path => 'lib/saas'
# MyApp/lib/saas/config/routes.rb
Rails::Application.routes.draw do |map|
namespace :saas do
resources :sessions
end
end
# Saas/lib/saas.rb
module Saas
require File.expand_path('../../config/engine', __FILE__)
end