Skip to content

Instantly share code, notes, and snippets.

@judofyr
judofyr / broken.js
Created December 9, 2011 22:13
Broken `buster static`
// app.js
NoBug = true;
// test/bug-test.js
buster.testCase('Buster', {
'should not be buggy': function() {
assert(NoBug);
}
});
class Parser
def force; self end
def |(other)
DisjunctiveParser.new(self, other)
end
def >>(other)
SequentialParser.new(self, other)
end
@judofyr
judofyr / valid_ruby.rb
Created November 17, 2011 15:20
Checks if a string is valid Ruby
def valid_ruby?(str)
catch(:valid) {
eval("BEGIN{throw :valid,true};#{str}")
}
rescue SyntaxError
false
end
p valid_ruby?("123")
p valid_ruby?("'")
#!/usr/bin/env ruby
require 'benchmark'
def bitmask
2 ** 32 - 1
end
def bitmask_with_assignment
overshoot = 2 ** 32
overshoot - 1
@judofyr
judofyr / override.rb
Created October 25, 2011 08:28
Method override
require 'camping'
Camping.goes :Ex
module Ex
use Rack::MethodOverride
end
module Ex::Helpers
SUPPORTED = %w[get post]
if defined?(Foo::THIS) && Foo::THIS == $0
p 'foo is executing'
end
@judofyr
judofyr / camping-csrf.rb
Created October 14, 2011 07:11
Protect Camping apps from CSRF
require 'camping'
require 'camping/session'
require 'rack/csrf'
Camping.goes :E
module E
use Rack::Csrf
include Camping::Session
end
diff --git a/lib/Mojo/Base.pm b/lib/Mojo/Base.pm
index 0fabd9a..19f5f87 100644
--- a/lib/Mojo/Base.pm
+++ b/lib/Mojo/Base.pm
@@ -8,6 +8,7 @@ require feature if $] >= 5.010;
# No imports because we get subclassed, a lot!
require Carp;
+require Scalar::Util;
require 'camping'
Camping.goes :Async
module Async
def service(*a)
return super unless respond_to?(:async?)
EM.next_tick do
send(@method, *a)
class Base; end
class Controller < Base
@@hello = :controller
end
class Base
@@hello = :base
end