Skip to content

Instantly share code, notes, and snippets.

View pmoran's full-sized avatar

Peter Moran pmoran

  • REA Group
  • Melbourne, Australia
View GitHub Profile
@pmoran
pmoran / gist:3011108
Created June 28, 2012 12:37
Clear property searches from cache
redis-cli -n 1 KEYS "cache:property:offers*" | xargs redis-cli -n 1 DEL
@pmoran
pmoran / newco-commit-msg
Created November 3, 2011 10:37
Git hook to make sure commit message contains stream identifier
#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
$regex = /^\[(Extranet|API|Consumer)\]/
if !$regex.match(message)
puts "COMMIT FAILED: your message doesn't start with [Extranet], [API] or [Consumer]"
exit 1
end
"filters": {
"pending": "function(doc, req) { if(doc.status != 'forwarded') { return true; } else { return false; }}"
}
"unprocessed" : {
"map" : "function(doc){ if(!doc.status) { emit(doc.requested_at, doc.text) } }"
}
def handle_notification(notification)
message = JSON.parse(notification)['doc']
Fiber.new {
result = despatch(message) # non-blocking
@db.save_doc(message.merge(status: "forwarded", result: result)) # blocking
}.resume
end
def despatch(message)
http = http_request({id: message['_id'], broadcast: message['text']})
{
"_id": "2c698404172067bf64c5be5daf5b4c4a",
"_rev": "1-5d0c994e3f4626e9e944977cc121b9d4",
"text": "first message",
"requested_at": "2011/01/17 09:54:17 +0000",
"priority": "medium"
}
CouchRest.database("http://localhost:5984/messages")
db.save_doc({text: "first message", requested_at: Time.now, priority: "medium"})
def run
EventMachine.run {
opts = { query: {feed: 'continuous', since: update_seq, heartbeat: 5000, filter: 'app/pending', include_docs: true} }
http = EventMachine::HttpRequest.new("#{DB_URL}/_changes").get opts
http.stream { |chunk| handle_notification(chunk) unless chunk =~ /^\n/ }
}
end
db.get(id)[:status]
# Ripped from cucumber-0.8.3/examples/watir/features/support/screenshots.rb
module Screenshots
if Cucumber::OS_X
def embed_screenshot(id)
`screencapture -t png reports/#{id}.png`
embed("#{id}.png", "image/png")
end
else
def embed_screenshot(id)
`import -window root reports/#{id}.png`