Skip to content

Instantly share code, notes, and snippets.

View dinks's full-sized avatar

Dinesh Vasudevan dinks

View GitHub Profile
@dinks
dinks / extract_params.rb
Created March 4, 2014 11:56
Extract Params in Middleware
rack_input = env["rack.input"].read
params = Rack::Utils.parse_query(rack_input, "&")
@dinks
dinks / vim.sh
Created March 3, 2014 20:22
Write as Root
:w !sudo tee %
@dinks
dinks / development.rb
Created February 25, 2014 10:06
Explain for longer queries
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@dinks
dinks / resuce_from.rb
Created February 9, 2014 12:42
Rescue from
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
private
def handle_not_found
# ...
end
end
@dinks
dinks / links.txt
Created January 25, 2014 20:33
Nice Capybara Links
@dinks
dinks / test.sh
Last active July 26, 2018 17:02
ISP Bad?
# Get the-1m.csv from Alexa http://www.alexa.com/topsites (right hand side of page)
for i in `head -n 1000 top-1m.csv | cut -f2 -d,`; do
echo "Site: $i";
diff <(curl --ipv4 -s -v --dns-servers 66.x.x.4,66.x.x.4 --url http://$i/ 2>&1 | grep -v "0x" | grep -v "Date: ") <(curl --ipv4 -s -v --dns-servers 8.8.8.8,8.8.4.4 --url http://$i/ 2>&1 | grep -v "0x" | grep -v "Date: ");
done > 1000.diff.txt
@dinks
dinks / review.txt
Created January 6, 2014 11:58
When Reviewing
Look at
General Unit Testing
Comment and Coding Conventions
Error Handling
Resource Leaks
Thread Safety
Control Structures
Performance
Functionality
Security
@dinks
dinks / spring.rb
Created January 4, 2014 12:54
Reload for FactoryGirl in Spring
Spring.after_fork { FactoryGirl.reload }
@dinks
dinks / .travis.yml
Created January 3, 2014 10:45
Use updated bundler for Ruby 2.1.0 as minitest fails to install
cache: bundler
language:
- ruby
before_install: gem install bundler -v=1.5.1
install:
- 'bundle install'
rvm:
- 1.9.3
- 2.0.0
- 2.1.0