Skip to content

Instantly share code, notes, and snippets.

View adambeynon's full-sized avatar

Adam Beynon adambeynon

View GitHub Profile
class User < Vienna::Model
attributes :first_name, :last_name
end
user = User.new
first = Frappuccino::Stream.new(user).capture(:changed_first_name)
last = Frappuccino::Stream.new(user).capture(:changed_last_name)
# last name is any change to first or last name
last_name = first.merge(last).map { "#{user.first_name} #{user.last_name}" }
@adambeynon
adambeynon / promises.rb
Created December 22, 2013 21:32
example promises
Product.find(1).then do |product|
puts "product: #{product}"
end.else do
puts "failed :("
end
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
require 'opal'
require 'rails_templates'
p Template.paths
# => ['login', 'logout', 'user', 'user/new']
@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
// runtime
Opal.modules = {};
Opal.register = function(name, body) {
Opal.modules[name] = body;
};
Opal.require = function(name) {
var module = Opal.modules[name];
module LocalStorage
def self.[](name)
`localStorage.getItem(name)`
end
def self.[]=(name, value)
`localStorage.setItem(name, value)`
end
def self.key?(name)
@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
.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
require 'opal'
require 'sinatra'
get '/' do
<<-EOS
<!doctype html>
<html>
<head>
<script src="/assets/application.js"></script>
</head>