Skip to content

Instantly share code, notes, and snippets.

Avatar

Gaurav Saini gauravsaini23

  • Trantor
  • Chandigarh
View GitHub Profile
View roman_number.rb
class RomanNumber
ROMAN_NUMBER = { I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000 }
def initialize(roman)
View amqp_server.rb
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
@gauravsaini23
gauravsaini23 / apply_maxlength.js
Created Feb 12, 2013
apply maxlength attribute to textarea (for ie)
View apply_maxlength.js
$('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));
}
});
View assets.rb
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 / queued_delivery.rb
Created Apr 23, 2012
Delay all mails in application
View queued_delivery.rb
# 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
@gauravsaini23
gauravsaini23 / web_steps.rb
Created Dec 15, 2011 — forked from richardlawrence/gist:1299371
Convert a Capybara table to something you can diff with a Cucumber table
View web_steps.rb
# 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 / print_sql_queries
Created Nov 25, 2011
Print sql queries in console rails 3
View print_sql_queries
Put this in environments/development.rb
#enable sql queries for rails console
ActiveRecord::Base.logger = Logger.new(STDOUT)