Skip to content

Instantly share code, notes, and snippets.

@samstokes
samstokes / dg_loop_syntaxen.rb
Created November 7, 2011 23:01
DG loop combinator thinking
# Hmmm
DG::loop_until { url.present? && chunks_done < 25 }.body do
make_http_request(stuff, things, other_things).safe_callback do |blah|
blah
end
end.transform
# Yum
DG::loop_until(lambda { url.present? && chunks_done < 25 }) do
make_http_request(stuff, things, other_things).safe_callback do |blah|
@samstokes
samstokes / methods_returning.rb
Created October 21, 2011 22:44
Stick this in your .irbrc and smoke it
def methods_returning(answer, *args)
# probably want to filter out some methods
# e.g. ones that mutate their receiver...
blacklist = %w()
(methods - blacklist).select do |method|
guinea_pig = begin
clone
rescue TypeError => e
raise unless e.message =~ /can't clone/
@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> {
@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 <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 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 / 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 / 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 / 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
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: