Skip to content

Instantly share code, notes, and snippets.

Muddling with Modules
Goals:
How do most of us use modules?
How do we change the way we use modules?
Topics:
Including/Extending
Namespacing
Mixing In
@dgtm
dgtm / gist:4983553
Last active December 13, 2015 22:19
class SheetWorker
include Sidekiq::Worker
sidekiq_options queue: :critical, :retry => 3
def perform(id)
sheet = Sheet.find(id)
if sheet.failed?
sheet.resend_failed_sheet
end
begin
@dgtm
dgtm / gist:4130055
Created November 22, 2012 08:50
Phase I
HTMLHelper
<repl type="ruby">
<code file="timer" operation="append/create">
require 'lib/clock.rb'
class Timer
def tick
Clock.new.rewind
end
end
</code>
@dgtm
dgtm / gist:3982074
Created October 30, 2012 18:28
Board Sketch
class Board
#properties
attr_accessor :location
attr_accessor :width
attr_accessor :height
attr_accessor :name
#relationships
attr_accessor :image
attr_accessor :contract
@dgtm
dgtm / gist:3799134
Created September 28, 2012 10:50
R
results1@surehire.mailgun.org,
results2@surehire.mailgun.org,
results3@surehire.mailgun.org,
results4@surehire.mailgun.org,
results5@surehire.mailgun.org,
results6@surehire.mailgun.org,
results7@surehire.mailgun.org,
results8@surehire.mailgun.org,
results9@surehire.mailgun.org,
results10@surehire.mailgun.org,
@dgtm
dgtm / gist:3797553
Created September 28, 2012 01:54
sca
package recfun
import common._
object Main {
def main(args: Array[String]) {
println("Pascal's Triangle")
for (row <- 0 to 10) {
for (col <- 0 to row)
print(pascal(col, row) + " ")
println()
@dgtm
dgtm / gist:3617231
Created September 4, 2012 05:44
SH
Phase I
First PDF is uploaded and it is sent to Sidekiq.
If Sidekiq dies and it remains in the Q Backlog infinitely, what do we do?
App precodes: rotates, crops, creates decodings
Failures here are retried thrice, if no success, send email to us and SureWire
Do this yourself / App Error has occurred
Tests are scanned for integrity
Emails are sent for no tests, incomplete test set, unidentified pages and processable pages
def call(worker, msg, queue)
begin
if msg['retry_count'] && msg['retry_count'] >= @max_retries
.....
.....
else
yield
end
rescue => e
raise
@dgtm
dgtm / gist:3507092
Created August 29, 2012 05:26
Sidekiq Trace
2012-08-28T19:13:01Z 25218 TID-117y84 SecondaryTestProcessor MSG-zeneo INFO: start
2012-08-28T19:13:11Z 25218 TID-117y84 WARN: {"retry"=>true, "queue"=>"critical", "backtrace"=>40, "class"=>"SecondaryTestProcessor", "args"=>["503d1443da756c61fa000125"], "jid"=>"2eak6j7a1Kp/C4N47hEZBg=="}
2012-08-28T19:13:11Z 25218 TID-117y84 WARN: No transition found for event sent_for_work
2012-08-28T19:13:11Z 25218 TID-117y84 WARN: /usr/local/rvm/gems/ruby-1.9.3-p194/bundler/gems/stateflow-1e526266a2b1/lib/stateflow/event.rb:15:in `fire'
/usr/local/rvm/gems/ruby-1.9.3-p194/bundler/gems/stateflow-1e526266a2b1/lib/stateflow.rb:73:in `fire_event'
/usr/local/rvm/gems/ruby-1.9.3-p194/bundler/gems/stateflow-1e526266a2b1/lib/stateflow.rb:43:in `block (2 levels) in stateflow'
/home/deploy/application/releases/20120828110620/app/models/document.rb:295:in `send_secondary_pages'
/home/deploy/application/releases/20120828110620/app/workers/secondary_test_processor.rb:13:in `block in perform'
/usr/local/rvm/gems/ruby-1.9.3-p194/bundler/
@dgtm
dgtm / x.rb
Created August 28, 2012 15:19 — forked from practicingruby/x.rb
class EventHandler
def initialize
@callbacks = Hash.new { |h,k| h[k] = [] }
end
def on(event, callback)
@callbacks[event] << callback
end
def trigger(event, *args)