Skip to content

Instantly share code, notes, and snippets.

require 'thread'
class Foo
@@count = 0
def self.increment
@@count += 1
end
def self.count
class Student
has_many :tracks
has_many :assignments, through: :tracks, class_name: 'Assessment'
end

Abstraction Suggestions

Summary: use good/established messaging patterns like Enterprise Integration Patterns. Don't make up your own. Don't expose transport implementation details to your application.

Broker

As much as possible, I prefer to hide Rabbit's implementation details from my application. In .Net we have a Broker abstraction that can communicate through a lot of different transports (rabbit just happens to be our preferred one). The broker allows us to expose a very simple API which is basically:

  • publish
  • request
  • start/stop subscription
*filter
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT
# Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow all outbound traffic - you can modify this to only allow certain traffic
#!/bin/sh
/sbin/iptables-restore < /etc/iptables.firewall.rules
#==============================================================================
# Resources
#==============================================================================
#
# Math and Logic - http://www.tutorialspoint.com/ruby/ruby_operators.htm
#
# Flow control:
# if/else - http://www.codecademy.com/glossary/ruby/if-unless-elsif-and-else
# looping - http://ruby.bastardsbook.com/chapters/loops/
#
#!/usr/bin/env ruby
require 'set'
class Node
attr_accessor :email, :neighbors
def initialize(email)
@email = email
@neighbors = Set.new
end
# http://www.programcreek.com/2013/12/leetcode-solution-of-longest-palindromic-substring-java/
require 'rspec'
def dynamic_lps(str)
return nil unless str.is_a?(String)
return str if str.length <= 1
longest_palindrome = ''
memo = Array.new(str.length) { Array.new(str.length) }
traceroute to digitalocean.com (141.101.115.8), 64 hops max, 52 byte packets
1 l100.nycmny-vfttp-226.verizon-gni.net (173.56.121.1) 4.101 ms 4.699 ms 2.971 ms
2 g1-1-3-3.nycmny-lcr-22.verizon-gni.net (130.81.180.4) 10.167 ms 11.152 ms 11.700 ms
3 ae4-0.ny5030-bb-rtr1.verizon-gni.net (130.81.163.224) 30.231 ms *
ae0-0.ny5030-bb-rtr1.verizon-gni.net (130.81.209.118) 39.039 ms
4 * 0.xe-3-2-0.il2.nyc9.alter.net (152.63.26.93) 7.402 ms
3.et-2-0-1.tl2.nyc1.alter.net (140.222.227.34) 7.501 ms
5 2.ae1.xt1.nyc4.alter.net (140.222.228.119) 31.797 ms
0.ae2.xl4.ewr6.alter.net (140.222.228.45) 49.313 ms
2.ae0.xt2.nyc4.alter.net (140.222.227.27) 96.378 ms
# NOTE: All model inheriting this method must implement a #publish! method.
module Publishable
def publish_to!(batch)
publish_parents!(batch)
publish_children!(batch)
end
def publish!
raise 'implement publish! on the inheriting class'
end