Skip to content

Instantly share code, notes, and snippets.

Peter Moran pmoran

Block or report user

Report or block pmoran

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pmoran
pmoran / gist:3011108
Created Jun 28, 2012
Clear property searches from cache
View gist:3011108
redis-cli -n 1 KEYS "cache:property:offers*" | xargs redis-cli -n 1 DEL
@pmoran
pmoran / newco-commit-msg
Created Nov 3, 2011
Git hook to make sure commit message contains stream identifier
View newco-commit-msg
#!/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
View gist:787825
"filters": {
"pending": "function(doc, req) { if(doc.status != 'forwarded') { return true; } else { return false; }}"
}
View gist:787765
"unprocessed" : {
"map" : "function(doc){ if(!doc.status) { emit(doc.requested_at, doc.text) } }"
}
View gist:787763
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']})
View gist:787759
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
View gist:787753
{
"_id": "2c698404172067bf64c5be5daf5b4c4a",
"_rev": "1-5d0c994e3f4626e9e944977cc121b9d4",
"text": "first message",
"requested_at": "2011/01/17 09:54:17 +0000",
"priority": "medium"
}
View gist:787751
CouchRest.database("http://localhost:5984/messages")
db.save_doc({text: "first message", requested_at: Time.now, priority: "medium"})
View gist:739583
# 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`
You can’t perform that action at this time.