Skip to content

Instantly share code, notes, and snippets.

View jasonngpt's full-sized avatar

Jason Ng PT jasonngpt

View GitHub Profile
@jasonngpt
jasonngpt / sinatra_rspec_session
Created November 27, 2013 03:34
Sinatra RSpec Session Variables
# my_test.rb (first line, or at least before you require your 'my_app.rb')
ENV['RACK_ENV'] = 'test'
# my_app.rb (your sinatra application)
enable :sessions unless test?
# my_test.rb (in your test block)
session = {} OR session = { "username" => "test" }
get '/', {}, 'rack.session' => session
assert_equal 'value', session[:key]
@jasonngpt
jasonngpt / sinatra_rspec_redirect
Created November 27, 2013 03:29
Sinatra RSpec Testing for Redirect
it "Homepage should redirect to locations#index" do
get "/"
last_response.should be_redirect # This works, but I want it to be more specific
follow_redirect!
last_request.url.should == 'http://example.org/locations'
end
@jasonngpt
jasonngpt / vim_f_key
Created October 26, 2013 02:14
Vim F key
If you press the "f" key in normal mode, Vim will move the cursor forward to whatever character you input after "f" is pressed. As an example, consider the following line:
a quick brown fox
If the cursor was at the absolute beginning of the line, and you pressed "fb" in normal mode, Vim would move the cursor so that it was positioned over the "b" in "brown".
If you press "F", Vim will move the cursor backwards instead of forward. Given the previous sentence, if pressed "Fq", and the cursor was at the end of the line, it would move to the "q" in "quick".
@jasonngpt
jasonngpt / 0_reuse_code.js
Created October 13, 2013 16:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console