Skip to content

Instantly share code, notes, and snippets.

View millisami's full-sized avatar
🎯
Focusing on landing a Web3 Job

Sachin Sagar Rai millisami

🎯
Focusing on landing a Web3 Job
View GitHub Profile
## Run document
{
"title": "Find info for these 50 companies",
"line_id": 23453453,
"order": {"amount": 23454, "service_charge": 2342},
}
## Initial Unit document
{

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@millisami
millisami / throw-catch.rb
Created July 13, 2011 10:13 — forked from avdi/throw-catch.rb
throw/catch demo code for RubyLearning article
require 'rubygems'
require 'mechanize'
MAX_PAGES = 6
def each_google_result_page(query, max_pages=MAX_PAGES)
i = 0
a = Mechanize.new do |a|
a.get('http://google.com/') do |page|
search_result = page.form_with(:name => 'f') do |search|
@millisami
millisami / cygwin_setup.txt
Created August 22, 2011 05:24 — forked from zoras/cygwin_setup.txt
install all the packages in cygwin
# Install all the packages required for using ruby on rails in cygwin
# Cygwin is a Linux-like environment for MS Windows.
# Download the Cygwin setup.exe from http://www.cygwin.com/setup.exe
# Few packages name and description
# inetutils # telnet(1)
# ncurses # see Terminator FAQ
# openssh # SSH (client and server, though the server's not so great)
@millisami
millisami / god_resque.rb
Created September 5, 2011 14:26 — forked from gravis/god_resque.rb
God monitoring files for resque
# Copyright (c) 2010 Tech-Angels
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
@millisami
millisami / all.god
Created September 5, 2011 18:18 — forked from nragaz/all.god
God configs for starting Resque and Unicorn
PID_DIR = '/srv/myapp/shared/pids'
RAILS_ENV = ENV['RAILS_ENV'] = 'production'
RAILS_ROOT = ENV['RAILS_ROOT'] = '/srv/myapp/current'
BIN_PATH = "/home/rails/.rvm/gems/ree-1.8.7-2010.02/bin"
God.log_file = "#{RAILS_ROOT}/log/god.log"
God.log_level = :info
%w(unicorn resque).each do |config|
God.load "#{RAILS_ROOT}/config/god/#{config}.god"
@millisami
millisami / email_validator.rb
Created September 20, 2011 10:14 — forked from jcf/email_validator.rb
Rails 3 Email Validator
require 'mail'
class EmailValidator < ActiveModel::EachValidator
attr_reader :record, :attribute, :value, :email, :tree
def validate_each(record, attribute, value)
@record, @attribute, @value = record, attribute, value
@email = Mail::Address.new(value)
@tree = email.__send__(:tree)
@millisami
millisami / initializer.rb
Created November 1, 2011 09:08 — forked from thbar/initializer.rb
Removing sensitive resque args from airbrake notifications
Resque::Failure::SensitiveAirbrake.configure do |config|
config.api_key = @config['airbrake']['api_key']
config.params_filters << 'my_sensitive_job_arg'
config.secure = @config['airbrake']['secure']
config.proxy_host = @config['airbrake']['proxy_host']
config.proxy_port = @config['airbrake']['proxy_port']
config.host = @config['airbrake']['host']
config.logger = Logger.new(STDOUT)
end
@millisami
millisami / callback_disabler.rb
Created November 11, 2011 10:23 — forked from justinko/callback_disabler.rb
Disable raw filter callbacks in RSpec
# In spec/support/callback_disabler.rb
module CallbackDisabler
def self.store_callbacks(model, filters)
model = constantize(model)
filters.each do |filter|
model.send("_#{filter}_callbacks").each do |callback|
stored_callbacks[model] << {
filter: filter, kind: callback.kind, raw_filter: callback.raw_filter
}
@millisami
millisami / capybara_webkit_screenshot_env.rb
Created November 14, 2011 03:39 — forked from mattheworiordan/capybara_webkit_screenshot_env.rb
Cucumber and Capybara-Webkit automatic screenshots on failure
def screen_shot_and_save_page
require 'capybara/util/save_and_open_page'
path = "/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}"
Capybara.save_page body, "#{path}.html"
page.driver.render Rails.root.join "#{Capybara.save_and_open_page_path}" "#{path}.png"
end
begin
After do |scenario|
screen_shot_and_save_page if scenario.failed?