Skip to content

Instantly share code, notes, and snippets.

View perplexes's full-sized avatar

Colin Curtin perplexes

View GitHub Profile
# 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/
# }
#!/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
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
~/projects/github/coffee-script(master) $ bin/node_coffee -i
Error: The 'posix' module has been renamed to 'fs'
at Object.<anonymous> (/usr/local/lib/node/libraries/posix.js:1:69)
at [object Object].<anonymous> (node.js:966:23)
at [object Object].emitSuccess (node.js:242:15)
at [object Object].<anonymous> (node.js:666:21)
at [object Object].emitSuccess (node.js:242:15)
at node.js:512:29
at [object Object].wait (node.js:321:13)
at require (node.js:953:32)
~/projects/github/coffee-script(master) $ rlwrap bin/node_coffee -i
coffee> Function.prototype.curry: ((scope) ->
node.js:1023:9
~/projects/github/coffee-script(master) $
Function.prototype.curry: ((scope, rest...) ->
scope ||= this
(=> @apply(scope, rest)))