Skip to content

Instantly share code, notes, and snippets.

@dgtm
dgtm / Alias_Method.rb
Created April 12, 2012 08:22
Alias Method
class Animal
class << self
def query
where(name: "cat")
end
def query_as_array
criteria = send("query_as_criteria")
criteria.count == 0 ? nil : criteria.to_a
end
@dgtm
dgtm / gist:2977416
Created June 23, 2012 07:43 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@dgtm
dgtm / gist:3489255
Created August 27, 2012 14:57
Callback like Callbacks
module Actions
module Base
def email(args)
extend(Mail)
send(*args)
end
def statistics(m,*args)
extend(Statistics)
send(m,*args)
end
@dgtm
dgtm / gist:3498456
Created August 28, 2012 14:23
Cheap Callback Pass 1
module Actions
module Base
def email(args)
extend(Mail)
send(*args)
end
def statistics(m,*args)
extend(Statistics)
send(m,*args)
end
@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)
@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/
def call(worker, msg, queue)
begin
if msg['retry_count'] && msg['retry_count'] >= @max_retries
.....
.....
else
yield
end
rescue => e
raise
@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
@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: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,