Skip to content

Instantly share code, notes, and snippets.

module MLS
extend self
GRID = ("A".."Z").to_a
SQUARE = ("0".."9").to_a
SUB = ("a".."z").to_a
lat = 180.0
PARTS = [[18, GRID], [10, SQUARE], [24, SUB], [10, SQUARE]]
PARTS.map! { |div, part| [lat = lat / div, part] }
"SortedSet" behaves like "Array (sorted after every insert)" and "(insert in place)".
Rehearsal ---------------------------------------------------------------------
Array (unsorted) 0.120000 0.000000 0.120000 ( 0.120734)
Set (unsorted) 0.000000 0.000000 0.000000 ( 0.000302)
Array (sorted once) 0.130000 0.000000 0.130000 ( 0.121996)
Array (sorted after every insert) 0.350000 0.000000 0.350000 ( 0.355280)
SortedSet 0.120000 0.030000 0.150000 ( 0.151816)
Array (insert in place) 0.090000 0.000000 0.090000 ( 0.093471)
------------------------------------------------------------ total: 0.840000sec
if (!this.RubyScript)
RubyScript = {};
RubyScript.Base = function() {
function alloc(klass) {
var obj = new klass;
obj.ivars = {};
obj.meta = null;
return obj;
};
class Base; end
class Controller < Base
@@hello = :controller
end
class Base
@@hello = :base
end
require 'camping'
Camping.goes :Async
module Async
def service(*a)
return super unless respond_to?(:async?)
EM.next_tick do
send(@method, *a)
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;
@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
if defined?(Foo::THIS) && Foo::THIS == $0
p 'foo is executing'
end
@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]
#!/usr/bin/env ruby
require 'benchmark'
def bitmask
2 ** 32 - 1
end
def bitmask_with_assignment
overshoot = 2 ** 32
overshoot - 1