Skip to content

Instantly share code, notes, and snippets.

@bds
bds / gist:ee7d42e82a86d601489d
Created October 23, 2014 05:47
Disable Pry
DISABLE_PRY_RAILS=1 rails console
@bds
bds / gist:7dff642d43bbe481457b
Created October 1, 2014 20:52
Mongoid Finder Methods
mongoid-3.1.6/lib/mongoid/criterion/modifiable.rb
@bds
bds / keybase.md
Created September 18, 2014 00:41

Keybase proof

I hereby claim:

  • I am bds on github.
  • I am bds (https://keybase.io/bds) on keybase.
  • I have a public key whose fingerprint is F157 0BAD 213C 68E5 5989 5EB0 F101 7FA2 66D5 7F86

To claim this, I am signing this object:

@bds
bds / exception-one-liner.rb
Created September 17, 2014 17:16
Ruby Exception Oneliner
(rdb:1) begin model.association.find_by(label: field["name"]); rescue => e; puts e.class; end
@bds
bds / osx-i-love-you.rb
Last active August 29, 2015 14:02
say I love you
`say -v? | cut -f1 -d' '`.split("\n").each {|v| `say -v "#{v}" I love you`}
@bds
bds / find_xargs_grep_sed.sh
Created June 3, 2014 03:45
find, xargs, grep and sed
find . -name *spec.rb |xargs grep -l 86400| xargs sed -i '' 's/86400/10/g'
@bds
bds / green_line.rb
Created April 25, 2014 21:21
Ruby string to print a dotted green line
puts "\033[32m-\033[0m" * 79
@bds
bds / query_params_rack_parse.rb
Last active August 29, 2015 13:57
Parse HTTP request query parameters with Rack::Utils
require 'rack'
params = "car[][color]=blue&car[][doors]=2&car[][model][name]=acme&car[][model][country]=usa"
Rack::Utils.parse_nested_query(params)
@bds
bds / gist:9670328
Last active September 12, 2015 17:42
Test Rails endpoints from console with Rack::Test
require 'rack/test'
browser = Rack::Test::Session.new(Rack::MockSession.new(Fooproject::Application))
browser.get("/posts.json")
browser.post("/posts.json", {:id => 1})
@bds
bds / scrappy.rb
Created March 13, 2014 20:47
Scraping web pages with Ruby for fun and profit
# print the numbers 1 to 5
(1..5).each do |page|
puts page
end
# print a url string with a page number inside
(1..5).each do |page|
puts "http://blog/scripted.com/page/#{page}"
end