Skip to content

Instantly share code, notes, and snippets.

View adambeynon's full-sized avatar

Adam Beynon adambeynon

View GitHub Profile
Promise.new do |promise|
HTTP.get(url, :GET, opts) do |response|
if response.ok?
promise.resolve response
else
promise.reject response
end
end
end
$window.setTimeout -> do
a = $document.createElement 'div'
a.innerHTML = "hi there"
$document.body.appendChild a
puts a.innerHTML
end, 0
require 'opal'
require 'sinatra'
get '/' do
<<-EOS
<!doctype html>
<html>
<head>
<script src="/assets/application.js"></script>
</head>
.row
.col-md-8
%h2 Items
.col-md-3
%h2 Shopping List
= bind_unless cart_empty? do
%a.btn.btn-default#clear-cart(style="width: 50%")
= bind clear_title
@adambeynon
adambeynon / opal_js.md
Last active August 29, 2015 13:55
Notes/summary from weekend discussion (Jan, 31).

Notes/summary from weekend discussion (Jan, 31).

Variables: nil, true, false, self

nil == null == undefined

nil   # => null
true  # => true
false # => false
module LocalStorage
def self.[](name)
`localStorage.getItem(name)`
end
def self.[]=(name, value)
`localStorage.setItem(name, value)`
end
def self.key?(name)
// runtime
Opal.modules = {};
Opal.register = function(name, body) {
Opal.modules[name] = body;
};
Opal.require = function(name) {
var module = Opal.modules[name];
@adambeynon
adambeynon / bar.rb
Created January 9, 2014 14:03
Sprockets can only require dependencies before the current file - so we end up with code like this: ```ruby class Bar < Foo end class Foo end ```
class Bar < Foo
end
require 'opal'
require 'rails_templates'
p Template.paths
# => ['login', 'logout', 'user', 'user/new']
describe NewProductView do
# do we have to repeat this?
view NewProductView
it "tries to add product on click submit" do
expect(view).to receive(:add_product).once
find('#submit').click
end
end