Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sbellware's full-sized avatar

Scott Bellware sbellware

View GitHub Profile
12 Fallacies of Distributed Computing
1. The network is reliable (Bill Joy, Tom Lyon)
2. Latency isn't a problem (Bill Joy, Tom Lyon)
3. Bandwidth isn't a problem (Bill Joy, Tom Lyon)
4. The network is secure (Bill Joy, Tom Lyon)
5. The topology won't change (Peter Deutsch)
6. The administrator will know what to do (Peter Deutsch)
7. Transport cost isn't a problem (Peter Deutsch)
8. The network is homogeneous (James Gosling)
@sbellware
sbellware / unbound_method_owner_sketch.rb
Created August 15, 2019 20:10
UnboundMethod owner points to base class
class SomeClass
def some_method
end
end
C = Class.new(SomeClass)
m = C.instance_method(:some_method)
pp m.owner
@sbellware
sbellware / pg-dev-machine-config-changes.md
Created April 17, 2019 17:52
Some useful Postgres configuration changes for a dev machine

Some useful Postgres configuration changes for a dev machine:

log_connections = on
log_disconnections = on
log_statement = 'all'

Optionally, set log timestamps to local time

log_timezone = 'US/Central' # Or whatever your timezone is
@sbellware
sbellware / Gemfile.lock
Last active February 6, 2019 00:23
Eventide Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
confstruct (1.0.2)
hashie (~> 3.3)
eventide-postgres (1.0.0.0)
evt-consumer-postgres
evt-entity_snapshot-postgres
evt-entity_store
evt-async_invocation (1.0.0.0)
class Consumer
include Consumer::Postgres
handler SomeHandler
handler SomeOtherHandler
def error_raised(error, message_data)
if error.instance_of?(MessageStore::ExpectedVersion::Error)
self.(message_data)
else
handle Deposit do |deposit|
account_id = deposit.account_id
sequence = deposit.metadata.global_position
# Retry once if an expected version error is raised by the write
Retry.(MessageStore::ExpectedVersion::Error) do
account, version = store.fetch(account_id, include: :version)
# Idempotence protection using sequence numbers
unless sequence > account.sequence
handle SomeMessage do |some_message|
post_data = PostData.build(some_message)
Retry.(HTTPError, millisecond_intervals: [100, 200]) do
SomeHttpAPI.post(post_data)
end
end
@sbellware
sbellware / consumer.rb
Created November 28, 2018 03:32
Eventide Error Handling
class Consumer
# ...
def error_raised(error, message_data)
# Do something with the error
raise error
end
end
@sbellware
sbellware / component_host.rb
Last active November 28, 2018 03:30
Eventide Error Handling
ComponentHost.start(component_name) do |host|
# ...
host.record_error(error) do
SomeErrorReporter.(error)
end
end
module Events
class Opened
include Messaging::Message
attribute :account_id, String
attribute :customer_id, String
attribute :time, String
end
class Deposited