Skip to content

Instantly share code, notes, and snippets.

Nathan Appere nathan-appere

Block or report user

Report or block nathan-appere

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View pagination.txt
| 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 Jul 21, 2019
Bare logic for a functional organizer
View organizer.rb
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 Apr 6, 2018
Quick implementation of an event-broker with channels + topics
View event-broker.coffee
`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 Apr 5, 2018
Fake implementation of inter component PubSub mechanism
View pubsub.coffee
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: ->
View interactor_danger.rb
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."
View organizer.rb
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) }
]
View gist:404d0c1a65dfebe8da7d7be01bab3347
<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; }
View gist:163a7b368ba334df6b310cd8d0c3bbdf
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 Aug 29, 2015
Enforce interface manually because sometimes ruby lets you down.
View interface.rb
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
View Class instance variable inheritance
class A
@options = {}
class << self
def inherited(subclass)
subclass.options = {}
end
You can’t perform that action at this time.