Skip to content

Instantly share code, notes, and snippets.

View nathan-appere's full-sized avatar

Nathan Appere nathan-appere

View GitHub Profile
| D1 | D2 | D3
R1 | A | W | 0
R2 | A | W | 1
R3 | A | X | 2
R4 | A | X | 3
R5 | A | Y | 4
R6 | B | Y | 5
R7 | B | Z | 6
R8 | C | Z | 1
@nathan-appere
nathan-appere / organizer.rb
Last active July 21, 2019 16:31
Bare logic for a functional organizer
require 'contracts'
module Organizer
include Contracts
Contract KeywordArgs[list: ArrayOf[RespondTo[:call]], ctx: Optional[Hash]] => [Symbol, Hash]
def self.call(list:, ctx: {})
result = :ok
begin
@nathan-appere
nathan-appere / event-broker.coffee
Last active April 6, 2018 23:59
Quick implementation of an event-broker with channels + topics
`import Ember from 'ember'`
# Where we save channels.
# The format is:
# channels = { "components.auth" { "submit": { /* hash of callbacks */ } }}
channels = {}
# Given hash, search for keys that match a pattern and call "callback" on them
# Ex: forEachMatch({ "a.b.c": 1, "a.b": 2, "x.y": 3 }, 'a.b.c', fn) will call fn twice with: fn(1) and fn(2)
forEachMatch = (list, key, callback) ->
@nathan-appere
nathan-appere / pubsub.coffee
Last active April 5, 2018 19:01
Fake implementation of inter component PubSub mechanism
EventeableMixin = Ember.Mixin.create
# Handle eventBroker change, tricky one!
init: ->
if !@get('eventBroker')
@set('eventBroker', create_local_event_broker)
register_events_listeners()
register_events_listeners: ->
class Interactor1
def call
context.fail! error: 'Failure. This is lost.'
end
end
class Interactor2
def call
foreign_context = Interactor1.call!(b: 2)
puts "THIS WILL NEVER BE CALLED."
organize [
Interactors::Upgrade::EnsureAccountOwner,
->(ctx) { ctx.payment_source = ctx.current_subscription.payment_source },
Interactors::Upgrade::EnsureValidUpgrade,
->(ctx) { Interactors::Subscribe::CreateSubscription.call(ctx, ended_at: ctx.upgraded_at) }
]
<script>
hbspt.forms.create({
portalId: '453289',
formId: 'faafbc57-6c2f-49a6-87ef-02c8653fdb30',
submitButtonClass: 'submitbutton',
redirectUrl: 'https://www.localhost.twenty20.com/pricing?roadblock=skip',
// This is never called.
onFormSubmit: function() { console.log("---------- onFormSubmit"); debugger; },
// This one works find.
onFormReady: function() { console.log("---------- onFormReady"); debugger; }
curl https://api.stripe.com/v1/subscriptions
-u API_KEY:
-d plan=account1_subscription25_1462918904
-d customer=cus_8QbM9gs5JyjLGs
-d trial_end=1462942058
curl https://api.stripe.com/v1/subscriptions/sub_8QbO9XNSu8xEIX
-u API_KEY:
-d "metadata[account_id]=2&metadata[ignore_cancelation]=true&metadata[subscription_id]=19"
@nathan-appere
nathan-appere / interface.rb
Last active August 29, 2015 14:11
Enforce interface manually because sometimes ruby lets you down.
class Coupon
class << self
def enforce_interface!
methods = self.instance_methods(false)
[:m].each do |method_name|
unless methods.include? method_name
raise "#{method_name} should be implemented"
end
class A
@options = {}
class << self
def inherited(subclass)
subclass.options = {}
end