Skip to content

Instantly share code, notes, and snippets.

@rahul100885
rahul100885 / routes.rb
Created May 6, 2014 05:01
How to: override devise default routes of sign in and sign out
MyApp::Application.routes.draw do
# If you concern about SEO then send permanent redirect (301) on old routes to new routes
# It is always better to do this setting in web server that is in nginx or apache.
# Here I am showing how to do it in rails routes file
get '/users/sign_in', to: redirect("/sign-in")
get '/users/sign_up', to: redirect("/sign-up")
# Need to skip session and registration so that we can override them in devise_scope block
# If we not do so then default route of devise continue to work
devise_for :users, :skip => [:sessions, :registrations]
@rahul100885
rahul100885 / Email-header
Created May 7, 2014 17:36
Email header for gmail action button
Delivered-To: XXXX@mydomain.com
Received: by 10.229.25.199 with SMTP id a7csp15957qcc;
Wed, 7 May 2014 05:55:13 -0700 (PDT)
X-Received: by 10.182.241.67 with SMTP id wg3mr44908240obc.16.1399467313246;
Wed, 07 May 2014 05:55:13 -0700 (PDT)
Return-Path: <rahul100885@gmail.com>
Received: from mail-pd0-x22d.google.com (mail-pd0-x22d.google.com [2607:f8b0:400e:c02::22d])
by mx.google.com with ESMTPS id yb4si1843965pbb.403.2014.05.07.05.55.12
for <XXXX@mydomain.com>
(version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
@rahul100885
rahul100885 / largest_table.sql
Created July 2, 2014 12:09
Find largest size table ( Disk usage )
SELECT relname, PG_SIZE_PRETTY(PG_TOTAL_RELATION_SIZE(relid)) FROM pg_stat_all_tables WHERE schemaname != 'pg_toast' AND relname LIKE 'pg_%' ORDER BY PG_TOTAL_RELATION_SIZE(relid) DESC;
@rahul100885
rahul100885 / monitor_passenger_rails_instances
Created February 11, 2011 05:08
This script will kill a rails instance which is taking more than 500 MB and retsrat a request if it has served 100 requests
#!/bin/sh
while true; do
passenger-memory-stats | grep Rails:\ /home | awk ' { if($2 > 500) print "kill -9 " $1}' | bash
# above line will kill all the rails instances which are using memory more than 500MB
passenger-status | grep Processed: | awk ' { if($7 > 100) print "kill -6 " $3}' | bash
# above line will abort all rails instance who have processed 100 request.
@rahul100885
rahul100885 / sphinx
Created May 19, 2011 15:31
Simple starup service using ruby
#!/usr/bin/env ruby
RAILS_CODE_PATH='/home/rahul/workspace/livia_portal_3/livia_portal/'
RAKE_PATH='/usr/local/rvm/gems/ree-1.8.7-2010.02@global/bin/rake'
USER="rahul"
case ARGV[0]
when "start"
STDOUT.puts "called start"
system "su - #{USER} -c \"cd #{RAILS_CODE_PATH} && #{RAKE_PATH} ts:rebuild\""
@rahul100885
rahul100885 / redis.conf
Created August 23, 2011 06:32
Configuration for redis
# Redis configuration file example
# Note on units: when memory size is needed, it is possible to specifiy
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
@rahul100885
rahul100885 / redmine_heroku_deploy.sh
Created September 26, 2011 07:48
Deploy Redmine to Heroku
#!/bin/bash
set -e
REDMINE_URL="http://rubyforge.org/frs/download.php/75097/redmine-1.2.1.tar.gz"
S3_ACCESS_KEY_ID=""
S3_SECRET_ACCESS_KEY=""
S3_BUCKET_NAME=""
HEROKU_APP_NAME=""
@rahul100885
rahul100885 / passenger_status.rb
Created October 31, 2011 09:42 — forked from dan-manges/passenger_status.rb
munin plugin for passenger
#!/usr/bin/env ruby
def output_config
puts <<-END
graph_category App
graph_title passenger status
graph_vlabel count
sessions.label sessions
max.label max processes
require "benchmark"
val = (1..9).to_a
Benchmark.bm(7) do |x|
x.report("if:") {
val.each { |v|
if v == 9
a = 9
elsif v == 8
@rahul100885
rahul100885 / bench1.rb
Created December 22, 2011 09:45
Benchmarking for uuid and hex(16)
require 'benchmark'
require 'securerandom'
Benchmark.bm(7) do |x|
x.report("UUID") { SecureRandom.uuid }
x.report("hex(16)") { SecureRandom.hex(16) }
end
#Output