Skip to content

Instantly share code, notes, and snippets.

@samstokes
samstokes / perform_lookup_example.rb
Created March 20, 2011 05:54
Experimenting with SiteLookups on the console
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
@samstokes
samstokes / config.xml
Created March 21, 2011 21:30
Minimal Jenkins job to reproduce RVM Gemset PATH issue with rake-plugin
<?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>
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 / xmonad-irb-prompt.hs
Created June 14, 2011 22:24
XMonad snippet for IRB prompt
-- === 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
@samstokes
samstokes / something_controller.rb
Created June 30, 2011 02:31
API example of AJAP responses
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 / loggily.js
Created August 17, 2011 22:22
Example of scheduling code loggily
// 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 / reporting_controller.rb
Created August 18, 2011 23:51
Proposed API for controller error reporting
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 / it_should_include_such_that.patch
Created October 8, 2011 02:53
[].should include_such_that {|item| p(item) }
commit e5e4aebccc334809c355b7387dc1469e18be2377
Author: Sam Stokes <[email protected]>
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 / SerializableSerialization.java
Created October 17, 2011 08:16
One ISerialization to rule them all?
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import backtype.storm.serialization.ISerialization;
public class SerializableSerialization<T extends Serializable> implements ISerialization<T> {