Skip to content

Instantly share code, notes, and snippets.

View perplexes's full-sized avatar

Colin Curtin perplexes

View GitHub Profile
@perplexes
perplexes / sidekiq_middleware.rb
Created February 27, 2014 20:52
Sidekiq Middleware inspector
# Script to dump your current Sidekiq server middleware like `rake middleware`
# Drop this in script/sidekiq_middleware.rb and run:
# RAILS_ENV=production bundle exec sidekiq -r ./script/sidekiq_middleware.rb
puts "Eager loding Rails..."
require 'rails'
require 'sidekiq/rails'
require File.expand_path('./config/environment.rb')
::Rails.application.eager_load!
puts Sidekiq.server_middleware.entries.map(&:klass).join("\n")
### Keybase proof
I hereby claim:
* I am perplexes on github.
* I am perplexes (https://keybase.io/perplexes) on keybase.
* I have a public key whose fingerprint is E27F 1732 FE53 88CC F03B 3C84 3B74 C3C6 9C50 474E
To claim this, I am signing this object:
@perplexes
perplexes / Procfile
Created March 5, 2015 19:25
Flowdock groups for hubot
web: bin/hubot -a flowdock -n <<<bot name>>> --enable-slash
#!/usr/bin/env ruby
require 'contrib/resolver_libs/playdar_resolver'
$:.unshift(File.dirname(__FILE__))
require 'rhap'
class RhapsodyResolver < PlaydarResolver
def resolver_settings
{:name => "Rhapsody Resolver"}
end
# Base resolver class
# Subclass PlaydarResolver and override #results and #resolver_settings,
# we'll take care of the rest (even running it!)
require 'rubygems'
require 'json'
# set_trace_func proc { |event, file, line, id, binding, classname|
# STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname if file =~ /resolver/
# }
Sampling process 2173 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling TextMate (pid 2173) every 1 millisecond
Call graph:
1926 Thread_2507
1926 start
1926 _start
1926 NSApplicationMain
1926 -[NSApplication run]
1926 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
# Find the path of the Gem given. Toss this in your ~/.bashrc or ~/.profile
# Usage:
# $ gempath mechanize
# /Library/Ruby/Gems/1.8/gems/mechanize-0.9.3
#
# My use case: open up the gem code to inspect it.
# $ mate `gempath mechanize`
alias gempath='ruby -rubygems -e "puts Gem.cache.find_name(ARGV.first).first.loaded_from.gsub(/specifications/, %q(gems)).gsub(/\.gemspec/, %q())"'
class Object
# Yield ourself to the block given, and let the block determine the value to pass.
# This is like #tap, but "alter"s the output instead of ignoring it.
# Useful for conditional scoping, like:
# # For admins, show all posts. For others, show only public posts.
# @posts = Post.all.alter{|p| current_user.admin? ? p : p.public}
#
# Rather than: note the double assignment :(
# @posts = Post.all
# @posts = @posts.public unless current_user.admin?
diff --git a/lib/sinatras-hat/actions.rb b/lib/sinatras-hat/actions.rb
index 9424a10..24f9c1b 100644
--- a/lib/sinatras-hat/actions.rb
+++ b/lib/sinatras-hat/actions.rb
@@ -21,6 +21,9 @@ module Sinatra
end
map.action :update, '/:id', :verb => :put do |request|
+ if request.env["rack.input"].size > 0
+ request.params.merge!(Hash.from_xml(request.env["rack.input"].read))
I want to turn this into a programming contest. Everyone should do this using their favorite technique and language. But, I want to add three more challenges (that admittedly stack the deck in my favor).
1. create a stats collecting query decorate that measures the time it takes to execute the query
(assume you have a stats object that responds to #measure and takes a block: stats.measure { sleep 1.second }
2. read "configuration" from a hash like:
{ :timeout => 1.second, :stats => true }
that adds the timeout and stats decorators to the factory if present in the hash, otherwise not.
3. at the end write a program that REVERSES the order of the decorators. So if you did Timeout(Stats(Query)) make it Stats(Timeout(Query)). Note that you must do this programmatically so write a generic decorator reversing function. You may expand the proxy interface to have a method called "underlying", "delegate" or some such.
The contest is: do this in your language in as "elegant" a way as you like. The goal is clarity