This file contains 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 'redis' | |
require 'redis-namespace' | |
class Limiter | |
def initialize(name:, threshold:, interval:, time_span: 600, bucket_span: 5) | |
@name, @threshold, @interval, @time_span, @bucket_span = name, threshold, interval, time_span, bucket_span | |
raise ArgumentError if @interval > @time_span || @interval < @bucket_span | |
@redis ||= Redis::Namespace.new(:limiter, redis: $redis || Redis.new) |
This file contains 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
Code | |
$("button").single_double_click(function () { | |
alert("Try double-clicking me!") | |
}, function () { | |
alert("Double click detected, I'm hiding") | |
$(this).hide() | |
}) | |
This file contains 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
54.38.135.239:2549 | |
This file contains 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 Choke | |
def initialize(interval) | |
@interval = interval | |
@mutex = Mutex.new | |
end | |
def perform | |
thread, result = nil, nil | |
@mutex.synchronize do | |
thread = Thread.new { result = yield } |
This file contains 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
~/dev/parslet$ rvm use 1.8.7-p302 | |
Using /Users/ncr/.rvm/gems/ruby-1.8.7-p302 | |
~/dev/parslet$ bundle exec rspec spec/parslet/mem_stress_spec.rb | |
23.030000 1.290000 24.320000 ( 24.331595) | |
. | |
Finished in 24.33 seconds | |
1 example, 0 failures | |
~/dev/parslet$ rvm use 1.9.2 | |
Using /Users/ncr/.rvm/gems/ruby-1.9.2-p180 |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" | |
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" | |
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<SOAP-ENV:Body> | |
<SOAP-ENV:Fault> | |
<faultcode>ERR_NO_SESSION</faultcode> | |
<faultfactor>doGetItemsInfo - Wrong session</faultfactor> |
This file contains 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
# put this in config/initializers | |
class NoopArray < Array | |
def <<(e) | |
self | |
end | |
def push(e) | |
self | |
end |
This file contains 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
Started GET "/api/private/users/1" for 127.0.0.1 at Wed Jul 07 15:43:09 +0200 2010 | |
Processing by Api::Private::UsersController#show as HTML | |
Parameters: {"id"=>"1"} | |
Completed 401 Unauthorized in 1ms | |
NoMethodError (undefined method `new__session_path' for #<Devise::FailureApp:0x103260cd8>): | |
/Users/ncr/.bundle/ruby/1.8/gems/devise-1.1.rc2/lib/devise/failure_app.rb:50:in `send' | |
/Users/ncr/.bundle/ruby/1.8/gems/devise-1.1.rc2/lib/devise/failure_app.rb:50:in `redirect' | |
/Users/ncr/.bundle/ruby/1.8/gems/devise-1.1.rc2/lib/devise/failure_app.rb:30:in `respond' | |
/usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.beta4/lib/abstract_controller/base.rb:145:in `send_action' |
This file contains 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
irb(main):002:0> module A; def x; "x"; end end | |
=> nil | |
irb(main):003:0> module B; def x; "y"; end end | |
=> nil | |
irb(main):004:0> Class.new do include A; end.new.x | |
=> "x" | |
irb(main):005:0> Class.new do include B; end.new.x | |
=> "y" | |
irb(main):006:0> Class.new do include A; include B end.new.x | |
=> "y" |
This file contains 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
# Customizing your Responder to always redirect to the collection path (index action). | |
class AppResponder < ActionController::Responder | |
protected | |
# Overwrite navigation_behavior to redirect to the collection_location. | |
def navigation_behavior(error) | |
if get? | |
raise error | |
elsif has_errors? && default_action | |
render :action => default_action |
NewerOlder