Skip to content

Instantly share code, notes, and snippets.

@laser
laser / 00_templates.coffee
Last active September 24, 2016 23:45
Marionette Best Practices
# unless there's a really good reason to do so, a view should not be passed a reference to a preexisting DOM element
view = new BadPhoneInputView(el: $('#phone'))
# instead, write your markup as a string-property of the view prototype to be evaluated at render-time
class GoodPhoneInputView extends Backbone.Marionette.ItemView
template: "<input type='text' name='phone'><a class='submit' href='#'>submit</a>"
# this allows us to unit-test the view in-memory, independently of the document
@laser
laser / app_redis.rb
Last active August 29, 2015 13:56
prez
require 'barrister-redis'
require './service.rb'
container = Barrister::RedisContainer.new('./user_service.idl',
[HandlerA.new, HandlerB.new],
database_url: ENV['OPENREDIS_URL'],
list_name: 'user_service')
container.start
@laser
laser / loan_to_json.rb
Created March 12, 2014 20:26
loan.rb to json
# x = Loan.new
# x.attributes = process_parameters(params[:apply])
# x.to_json
{
"loan":{
"address_city":"Dallas",
"address_state":"TX",
"address_street":"101 Main Street",
"address_suite_number":"#101",
insert :: LogMessage -> MessageTree -> MessageTree
insert (Unknown _) t = t
insert m@(LogMessage _ ts1 _) t = case t of
(Leaf) -> Node Leaf m Leaf
(Node _ (Unknown _) _) -> t
(Node t1 m2@(LogMessage _ ts2 _) t2) -> case ts1 < ts2 of
True -> Node (insert m t1) m2 t2
False -> Node t1 m2 (insert m t2)
addSomethingToEach :: [Integer] -> [Integer]
addSomethingToEach list = map something list
where something n = case (n > 0) of
True -> 2
False -> 9
@laser
laser / 00_user_model.rb
Created April 14, 2014 17:22
Microservices
class User < ActiveRecord::Base
after_create :notify_added
validates :email, uniqueness: true
def notify_added
UserMailer.email(self).deliver
end
end
@laser
laser / user.rb
Created April 14, 2014 17:24
00: UserModel
class User < ActiveRecord::Base
after_create :notify_added
validates :email, uniqueness: true
def notify_added
UserMailer.email(self).deliver
end
end
@laser
laser / users_controller.rb
Created April 14, 2014 17:25
01: UsersController
class UsersController < ApplicationController
def index
@users = User.all
end
def new; end
def create
User.new(user_params).save!
@laser
laser / interface.idl
Created April 14, 2014 17:28
02: MailService IDL
// services/mail_service/interface.idl
interface MailService {
send_email(from string, to string, subject string, body string) bool
}
@laser
laser / interface.idl
Created April 14, 2014 17:29
03: UserService IDL
// services/user_service/interface.idl
struct UserProperties {
email string
full_name string
phone_number string [optional]
}
struct User extends UserProperties {
id int