This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // do this once dom is ready | |
| $(document).ajaxSend(function(e, xhr, options) { | |
| var token = $("meta[name='csrf-token']").attr("content"); | |
| xhr.setRequestHeader("X-CSRF-Token", token); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # BSON stores document keys as strings, so Hash keys are strings | |
| # when going into MongoDB and coming out. This extension allows | |
| # a developer to not worry as to whether or not the keys are | |
| # Strings or Symbols. | |
| # | |
| # This requires Mongoid 2.4.3+ and Rails 3. | |
| # | |
| # Instead of needing Rails you could just require ActiveSupport. In your Gemfile (or .gemspec) | |
| # gem "activesupport", ">= 3.0.0" | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # RSpec's subject method, both implicitly and explicitly set, is useful for | |
| # declaratively setting up the context of the object under test. If you provide a | |
| # class for your describe block, subject will implicitly be set to a new instance | |
| # of this class (with no arguments passed to the constructor). If you want | |
| # something more complex done, such as setting arguments, you can use the | |
| # explicit subject setter, which takes a block. | |
| describe Person do | |
| context "born 19 years ago" do | |
| subject { Person.new(:birthdate => 19.years.ago } | |
| it { should be_eligible_to_vote } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.host; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %W(INT TRAP).each do |sig| | |
| trap(sig) do | |
| puts "caught: #{sig}" | |
| raise "get outta here" | |
| end | |
| end | |
| x = Thread.new { | |
| (1..5).each do | |
| puts "working" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # usage: | |
| # $ chrome index.html | |
| function chrome() { | |
| open $@ --args --allow-file-access-from-files | |
| } | |
| # usage: | |
| # $ server | |
| alias server='open http://localhost:8000 && python -m SimpleHTTPServer' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'aquarium' | |
| module Gizmo | |
| class ExceptionHandling | |
| include Aquarium::DSL | |
| types = ['Gizmo::FindAll', 'Gizmo::Find', 'Gizmo::Make', 'Gizmo::Modify', 'Gizmo::Delete'] | |
| around :calls_to => [:call], :in_types => types do |jp, operation, *args| | |
| puts "inside around advice.. | |
| jp.proceed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| set -e | |
| if [ -d "generated" ] ; then | |
| echo >&2 "error: 'generated' directory already exists. Delete it first." | |
| exit 1 | |
| fi | |
| mkdir generated |