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
// returns a function that will invoke the callback 'delay' ms after it is last called | |
// eg. invoke the callback 500ms after the last time a key is pressed | |
// based on http://stackoverflow.com/questions/2219924/idiomatic-jquery-delayed-event-only-after-a-short-pause-in-typing-e-g-timew | |
// but fixes the following: | |
// (a) returns a unique timer scope on every call | |
// (b) propagates context and arguments from the last call to the returned closure | |
// and adds .cancel() and .fire() for additional callback control | |
// then of course, you could use underscore's _.debounce | |
// it doesn't have the .cancel and .fire, but you may not care :) | |
function delayedCallback(callback, delay) { |
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
try { | |
if (getLog().isTraceEnabled()) | |
getLog().trace("lookup : " + hostname); | |
// oh, lookup! | |
InetAddress ipAddress = InetAddress.getByName(hostname); | |
// NOTE: this is where it went bad on the AWS image | |
// *sigh* |
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
# | |
# included into vhosts/localhost.conf (*.by-ip) | |
# answers to :80 | |
# | |
# registered with FaceBook | |
location /forgiveness { | |
# no-trailing-/ case (the rewritten URI has a zero length) | |
if ($request_filename = '') { | |
rewrite (.*) $1/; |
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
# allows for Facebook pub / dev tunneling | |
# have to set the Cookie within the scope of the app | |
# can't use Firefox cookie editor to hack it | |
def tunnel | |
# how convenient! | |
value = params[:id] | |
# this is how we get pub / dev tunneling | |
# see support/nginx | |
if value == 'nil' |
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
specify "knowledge of nil" do | |
''.should_not be_nil | |
end | |
specify "numeric calculations" do | |
(355.0 / 113).should be_close(Math::PI, 0.1) | |
end | |
specify "changes made by a closure" do | |
array = [] |
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
def expect_raise(type=Spec::Mocks::MockExpectationError, &block) | |
abort 'block must be provided' unless block_given? | |
block.should raise_error(type) | |
end | |
specify "the basics" do | |
@mock.should_receive :hello | |
@mock.should_not_receive :goodbye | |
@mock.hello |
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
before(:each) do | |
Twitter::Client.send :public, :create_http_get_request | |
@client = Twitter::Client.new | |
@client_clone = Twitter::Client.new | |
end | |
it "produces a querystring with all the crazy stuff Twitter imagined" do | |
the_params = nil |
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
class Net::HTTPResponse | |
def self.mock(ops={}) | |
# defaults | |
ops = { | |
:http_version => '1.1', | |
:code => '200', | |
:message => 'OK', | |
:body => nil, | |
}.merge(ops || {}) |
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
@@config_mutex = Mutex.new | |
def configuration_mutex | |
@@config_mutex | |
end | |
alias :raw_http_connect :http_connect | |
def http_connect(*args, &block) | |
ops = (Hash === args.last) ? args.pop : {} | |
result = nil |
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
def observer_struct | |
@observer_struct ||= Struct.new(:channel, :stdout, :stderr, :exit_status, :exit_signal) | |
end | |
def observe_channel(ch, ops={}) | |
observer = observer_struct.new(ch, '', '', 0, nil) | |
is_puts = !!ops[:puts] | |
# stdout | |
ch.on_data do |ch, data| |
OlderNewer