Skip to content

Instantly share code, notes, and snippets.

View gauravsaini23's full-sized avatar

Gaurav Saini gauravsaini23

  • Trantor
  • Chandigarh
View GitHub Profile
@gauravsaini23
gauravsaini23 / print_sql_queries
Created November 25, 2011 09:53
Print sql queries in console rails 3
Put this in environments/development.rb
#enable sql queries for rails console
ActiveRecord::Base.logger = Logger.new(STDOUT)
@gauravsaini23
gauravsaini23 / web_steps.rb
Created December 15, 2011 11:31 — forked from richardlawrence/gist:1299371
Convert a Capybara table to something you can diff with a Cucumber table
# add this method to enable method tableish in a different way
module WithinHelpers
def tableish(id)
find('table' + '#' + id).all('tr').map { |row| row.all('th, td').map { |cell| cell.text.strip } }
end
end
World(WithinHelpers)
@gauravsaini23
gauravsaini23 / queued_delivery.rb
Created April 23, 2012 11:42
Delay all mails in application
# in config/application.rb
ActionMailer::Base.add_delivery_method :queued, Mail::QueuedDelivery
# in config/environment.rb
config.action_mailer.delivery_method = :queued
# in lib/mail/queued_delivery.rb
module Mail
class QueuedDelivery
set :max_asset_age, 2 ## Set asset age in minutes to test modified date against.
after "deploy:finalize_update", "deploy:assets:determine_modified_assets", "deploy:assets:conditionally_precompile"
namespace :deploy do
namespace :assets do
desc "Figure out modified assets."
task :determine_modified_assets, :roles => assets_role, :except => { :no_release => true } do
set :updated_assets, capture("find #{latest_release}/app/assets -type d -name .git -prune -o -mmin -#{max_asset_age} -type f -print", :except => { :no_release => true }).split
@gauravsaini23
gauravsaini23 / apply_maxlength.js
Created February 12, 2013 12:00
apply maxlength attribute to textarea (for ie)
$('textarea[maxlength]').live('keyup blur', function() {
// Store the maxlength and value of the field.
var maxlength = $(this).attr('maxlength');
var val = $(this).val();
// Trim the field if it has content over the maxlength.
if (val.length > maxlength) {
$(this).val(val.slice(0, maxlength));
}
});
@gauravsaini23
gauravsaini23 / amqp_server.rb
Created March 12, 2013 12:19
amqp implementation
require 'yaml'
######################
## SET CONFIGURATION
#####################
ENV['JAVA_HOME'] = '/usr/lib/jvm/java-6-openjdk-i386/'
APP_CONFIG = YAML.load_file(File.expand_path("./../../../config/instances/hcl.yml", __FILE__))[ARGV[0].to_s]
unless ARGV[0]
puts "Please pass on the environment param: development | test | production"
abort
class RomanNumber
ROMAN_NUMBER = { I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000 }
def initialize(roman)