Skip to content

Instantly share code, notes, and snippets.

View ben-ole's full-sized avatar

Benjamin Gaertig ben-ole

View GitHub Profile
@ben-ole
ben-ole / Paging.coffee
Last active August 26, 2016 14:09
Simple Navigation Component for FramerJS
# simple navigation componenent like on iOS
# put at the top of your file
class Paging
pages = Array()
constructor: (@bg_layer) ->
# push a new page on top
@ben-ole
ben-ole / form_helper.rb
Created February 23, 2017 09:29
Foundation Switch Rails Form Helper
module FormHelper
class ActionView::Helpers::FormBuilder
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper
def switch(name, options = {})
@switch_id = "#{@object_name}_#{name}"
lbl(name,options) + container(name,options)
end
@ben-ole
ben-ole / event_handler_test.ex
Created July 3, 2018 12:25
KaufmannEx TestSupport
defmodule Sample.EventHandlerTest do
use KaufmannEx.TestSupport.MockBus
test "Events Can Be published & observed" do
given_event(:"command.user.create", %{user_name: "Test User", user_email: "test@example.com"})
assert %{
payload: %{user_id: uknown_id}
} = then_event(:"event.test")
end
@ben-ole
ben-ole / publisher.ex
Last active July 3, 2018 12:34
Kafka publisher
defmodule Sample.Publisher do
def publish(event_name, payload, context \\ %{}, topic \\ :default) do
message_body = %{
payload: payload,
meta: event_metadata(event_name, context)
}
KaufmannEx.Publisher.publish(event_name, message_body, context)
@ben-ole
ben-ole / event_handler.ex
Created July 3, 2018 12:36
KaufmannEx EventHandler 2
defmodule Sample.EventHandler do
alias KaufmannEx.Schemas.Event
def given_event(%Event{name: :"command.user.create", payload: payload} = event) do
{:ok, user_info} = Sample.User.create(payload)
Publisher.publish(:"event.user.create", user_info, event.meta)
end
@ben-ole
ben-ole / event_handler.ex
Created July 3, 2018 12:37
KaufmannEx EventHandler 1
defmodule Sample.EventHandler do
alias KaufmannEx.Schemas.Event
def given_event(%Event{name: :"command.user.create", payload: payload} = event) do
{:ok, user_info} = Sample.User.create(payload)
Publisher.publish(:"event.user.create", user_info, event.meta)
end