Skip to content

Instantly share code, notes, and snippets.

View adambeynon's full-sized avatar

Adam Beynon adambeynon

View GitHub Profile
[1, 2, 3, 4].each do |a|
a
end
// [1, 2, 3, 4].$each($iter(function(a) { return a }, self));
Array.prototype.$each = function(block) {
if (typeof(block) === 'function' && block._isBlock) {
var block = block;
}
/*
class Foo
# some method to handle bananas
def do_it
42
end
def and_this
do_it
end
@adambeynon
adambeynon / overview.rb
Created October 15, 2013 16:07
vienna + rails = <3
# We want vienna to render our Product#show view...
class ProductController < ApplicationController
def show
@product = Product.find(...)
render :vienna => @product
end
end
# The `vienna` renderer will look for a view (Vienna::View) subclass that
$iter(self, '$it', "should do something", ($TMP_1 = function() {
return (1).$should()['$=='](2);
}), self);
@adambeynon
adambeynon / wrapper.rb
Last active December 26, 2015 09:09
wrapper override
class Array::Wrapper
def self.inherited(subclass)
real_subclass = Class.new(Array::Wrapper)
%x{
subclass._proto = real_subclass._proto;
subclass._alloc = real_subclass._alloc;
subclass.$new = real_subclass.$new;
subclass['$[]'] = real_subclass['$[]'];
@adambeynon
adambeynon / native.rb
Created October 29, 2013 09:50
Opal native with block
# Class.new
Foo = Class.new(Bar) do
def woosh
:kapow
end
end
# Native.new
LocalStorage = Native.new(`localStorage`) do
def [](key)
@adambeynon
adambeynon / opal_method_tables.md
Last active December 27, 2015 01:49
Method tables

Method tables

Stupid idea, but lets just look at the benefits/costs

We compile a ruby call currently as:

recv.$foo(1, 2, 3);
@adambeynon
adambeynon / opal_metadata.js
Created October 31, 2013 20:25
Opal Metadata
Opal.register_metadata([
{
"method": "Array#size",
"file": "opal/array.rb",
"line": 12,
"source": "# This method.......\ndef size;....\nend"
},
{
"method": "Array#slice",
describe "Timeouts" do
async "blah" do
default_timeout 100
set_timeout(4000) do
run_async { :ok }
end
end
end
module JqueryRspecHelpers
def stub_http(action, url, result)
expect(HTTP).to receive(action).with(url).and_yield(result)
end
end
describe User do
describe ".current" do
it "should make an http request for user details" do
stub_http(:get, '/current_user', { "name" => "Fred", "admin" => true })