Skip to content

Instantly share code, notes, and snippets.

@bds
bds / gist:8359654
Last active January 2, 2016 20:49
Mongo console commands
show dbs
use my_db
show collections
db.printCollectionStats()
db.things.find( {}, { _id:1 } ) # All documents ids
db.things.find ( { _id: ObjectId("daf3424234dsf12334f") } ).count()
@bds
bds / gist:8544104
Created January 21, 2014 17:16
Remove trailing whitespace from Vim
:%s/\s\+$//
@bds
bds / gist:8553090
Created January 22, 2014 03:34
Find Ruby puts statements polluting test output
find spec/ -type file | xargs grep "p " | cut -d " " -f 1 | sort | uniq
@bds
bds / gist:8946724
Created February 11, 2014 23:40
Parse 1st JSON result
JSON.parse(open("https://www.scripted.com/formats/").read).take(1)
@bds
bds / cookie_values
Created February 12, 2014 02:55
JavaScript one-liner for cookie values
@bds
bds / gist:9240609
Created February 26, 2014 22:58
Loop a shell command
for run in {1..10}
do
command
done
@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
@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 / 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 / green_line.rb
Created April 25, 2014 21:21
Ruby string to print a dotted green line
puts "\033[32m-\033[0m" * 79