Skip to content

Instantly share code, notes, and snippets.

100.times do |i|
Thread.new { puts "Index: #{i}"}
end
module DependencySupport
def self.included(base)
base.extend(ClassMethods)
end
# Substitutes a give dependency with a provided value
# will raise an exception if a provided dependency is missing
# @param [Sumbol] dependency_name
# @param [*] value
# @param [Integer] order_id order
# @return [Hash]
# @example
#
# teams: {
# members-with-goms: [45, 21, 41],
# members-with-orders: [21, 41],
# member-order-totals: {
# 45: 1400,
# 21: 1678
@joegaudet
joegaudet / cart_cleared.rb
Last active May 23, 2019 20:21
Better Wisper Usage
module Ordering
module Events
class CartCleared < ::Events::Event
values do
attribute :order_id, Integer
attribute :group_order_member_ids, Array[Integer]
attribute :order_item_ids, Array[Integer]
end
module Orders
class CreateTeamsMeta < FoodeeService
dependency :order_dao, Order
attr_accessor :order
# @param [Integer] order_id order
# @return [Hash]
# @example
@joegaudet
joegaudet / hash.rb
Created March 28, 2019 17:14
Hash Conflict Resolution
hash_a = {foo: 'bar', baz: 'qux'}
hash_b = {foo: 'baz'}
hash_c = hash_a.merge(hash_b) do |key, old, new|
[old, new]
end
hash_c == {
foo: ['bar', 'baz'],
baz: 'qux'
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
queryParams: ['foo'],
foo: '',
actions: {
def self.exercise_contact(s = new.login, contact_id: 108080)
puts "Fetching a contact by id #{contact_id}"
s.flipper[:use_salesforce_connect].disable
old_contact = s.contacts.get(contact_id)
s.flipper[:use_salesforce_connect].enable
new_contact = s.contacts.get(contact_id)
raise 'Contacts did not match' unless new_contact.to_h <= old_contact
end
@joegaudet
joegaudet / broadcaster.rb
Last active December 11, 2018 20:23
Update to the dependency system to support two types of null substitutes, one where the only public interface is call, and one where it is any method. This allows us to more simply test object boundaries.
module Broadcasters
class OrderBroadcaster
include Wisper::Publisher
include DependencySupport::NullSubstitute
def changed(order)
// do some stuff
end
end
end