Skip to content

Instantly share code, notes, and snippets.

@samstokes
samstokes / it_should_include_such_that.patch
Created Oct 8, 2011
[].should include_such_that {|item| p(item) }
View it_should_include_such_that.patch
commit e5e4aebccc334809c355b7387dc1469e18be2377
Author: Sam Stokes <sam@rapportive.com>
Date: Wed Oct 5 17:02:47 2011 -0700
[2, 4, 6].should_not include_such_that(&:odd?)
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index c6b006b..03aeec5 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@samstokes
samstokes / reporting_controller.rb
Created Aug 18, 2011
Proposed API for controller error reporting
View reporting_controller.rb
class TestController < ApplicationController
report RuntimeError, :status => 411, :error_code => :oh_noes
report ArgumentError, :status => 407, :error_code => :eeep do |exception, report|
report[:nartiploom] = Time.now
report[:banditry] = exception.class.name
end
report IndexError, :status => 404
def index
case params[:boom]
when 'arg'
@samstokes
samstokes / loggily.js
Created Aug 17, 2011
Example of scheduling code loggily
View loggily.js
// no annotation
setTimeout(function () { /* something that blows up horribly */ }, 1000);
// annotated, behaves identically unless it blows up
setTimeout(loggily("doing something hairy", function () { /* something that blows up horribly */ }), 1000);
@samstokes
samstokes / something_controller.rb
Created Jun 30, 2011
API example of AJAP responses
View something_controller.rb
class SomethingController
include AjapController
defer_response :only => :slow_operation
def slow_operation
later do |ajap|
Leviathan.do_something_very_slowly.callback do |result|
ajap.respond :status => 200, :message => result
end
end
@samstokes
samstokes / xmonad-irb-prompt.hs
Created Jun 14, 2011
XMonad snippet for IRB prompt
View xmonad-irb-prompt.hs
-- === Utilities === {{{1
withLabels :: (a -> b) -> [a] -> [(b, a)]
withLabels label items = (label <$> items) `zip` items
labelled :: [a] -> (a -> b) -> [(b, a)]
labelled = flip withLabels
----- Ruby prompts ----- {{{3
View foo.patch
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index b811e60..34323e3 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -33,6 +33,38 @@ class ApplicationController < ActionController::Base
protected
+ # ActionController::Base calls this before processing each controller action.
+ # The default implementation produces two log entries:
@samstokes
samstokes / config.xml
Created Mar 21, 2011
Minimal Jenkins job to reproduce RVM Gemset PATH issue with rake-plugin
View config.xml
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description>https://github.com/jenkinsci/rake-plugin/issues/3</description>
<keepDependencies>false</keepDependencies>
<properties>
<com.coravy.hudson.plugins.github.GithubProjectProperty>
<projectUrl>https://github.com/jenkinsci/rake-plugin/</projectUrl>
</com.coravy.hudson.plugins.github.GithubProjectProperty>
</properties>
@samstokes
samstokes / perform_lookup_example.rb
Created Mar 20, 2011
Experimenting with SiteLookups on the console
View perform_lookup_example.rb
def lookup_url(ident); "http://favstar.fm/users/#{ident}"; end
def save_result(ident, result); puts Hpricot(result).at(:title).inner_text; end
def logger; Rails.logger; end
def name; 'console'; end
include Point::SiteLookup
perform_lookup! 'samstokes'
# console is querying http://favstar.fm/users/samstokes
# @samstokes' (Sam Stokes) most faved tweets
You can’t perform that action at this time.