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
@adambair
adambair / gist:1299611
Created October 19, 2011 20:46
pry is awesome.
# use instead of rails console
pry -r ./config/environment.rb
# for debugging in code put this anywhere:
binding.pry
# then check your console (rails server window) and type:
help
# win
@justinko
justinko / callback_disabler.rb
Created September 2, 2011 00:20
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
}
class Foo < ActiveRecord::Base
include Models::Scopes::Order
default_scope recently_updated # didn't realize you could do this
end

Ruby Debugger

Most of the time simple output statements using warn, raise, or a logger will help you find your issue. But sometimes you need the big guns, and that means ruby-debug.

Ruby-Debug

The ruby-debug package has had some rocky times during the transition from Ruby 1.8.7 to 1.9.2 and beyond. But now, finally, the debugger is reliable and usable.

Installation

@minhajuddin
minhajuddin / gist:1043322
Created June 23, 2011 19:03 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@leshill
leshill / gist:870866
Created March 15, 2011 15:17
Cucumber/Capybara JS alert handling
# Add this to more_web_steps.rb
# Selenium docs: http://code.google.com/p/selenium/wiki/RubyBindings#Javascript_Alert/Confirm today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end
@visnup
visnup / Screen shot 2011-02-07 at 4.37.04 PM.png
Created February 8, 2011 00:37
# trippy mongodb colorized logging by statement type
Screen shot 2011-02-07 at 4.37.04 PM.png
@mikhailov
mikhailov / installation.sh
Created November 23, 2010 15:18
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@cmilfont
cmilfont / ruby_install.sh
Created October 20, 2010 14:14
ruby_install.sh
#!/usr/bin/env bash
sudo apt-get install sed grep tar curl
sudo apt-get install zlibc zlib1g zlib1g-dev zlib-bin ssh perl openssl subversion libcurl3 expat
sudo apt-get install git libxml2 libxml2-dev ruby-dev libxslt1-dev
sudo apt-get install mysql-server libmysqlclient-dev imagemagick librmagick-ruby libmagick++3 libgraphicsmagick3 libgraphicsmagick1-dev libmagick++-3 libpng3
sudo apt-get install libopenssl-ruby libssl-dev libssl0.9.8
sudo apt-get install libreadline5-dev