This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Search < ActiveRecord::Base | |
# We want to reference various models | |
belongs_to :searchable, :polymorphic => true | |
# Wish we could eliminate n + 1 query problems, | |
# but we can't include polymorphic models when | |
# using scopes to search in Rails 3 | |
# default_scope :include => :searchable | |
# Search.new('query') to search for 'query' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Figured out by Craig on the macruby-devel mailing list | |
framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/DictionaryServices.framework' | |
word = 'History' | |
word_len = DCSGetTermRangeInString(nil, word, 0); | |
result = DCSCopyTextDefinition(nil, word, word_len) | |
puts "Definition for: #{word}" | |
puts result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack' | |
require 'rack/builder' | |
require 'rack/lobster' | |
class MagLevTransactionWrapper | |
def initialize(app) | |
@app = app | |
end | |
def call(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config.gem 'rack-probe' | |
config.middleware.use 'Rack::Probe' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save the time a request comes in | |
rack*:::request_start | |
{ | |
self->start = timestamp; | |
self->flip = 1; | |
} | |
// Save the request's path | |
rack*:::path | |
/ self->flip == 1 / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Save the time a request comes in | |
rack*:::request_start | |
{ | |
self->start = timestamp; | |
} | |
// Save the difference between the request's start and finish | |
rack*:::request_finish | |
{ | |
@length[self->path] = quantize(timestamp - self->start); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Our IRS (Internal Request Service) agent | |
require 'rack/probe' | |
# Let's add some nice phrases to our app's repertoire | |
responses = ['Clap clap clap!', 'Oh noes, oh noes, oh noes!', 'Oh yeah, oh yeah, oh yeah!'] | |
# Our friendly app. He's a cheery fellow, get's easily agitated | |
app = Proc.new{ [200, {'Content-Type' => 'text/html'}, responses[rand(3)] } | |
# The agent slips in between the paper trail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Hi! Welcome to your new weight-loss program, tenplustwo. | |
# First thing's first. We need a way to communicate. | |
def shout( msg ); `growlnotify -s -m "#{msg}"`; end | |
# Put on your running shoes. | |
running = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Sleep until we need to wake up to honour D options controlling | |
* consumption rates. | |
*/ | |
VALUE dtrace_hdl_sleep(VALUE self) | |
{ | |
dtrace_handle_t *handle; | |
Data_Get_Struct(self, dtrace_handle_t, handle); | |
dtrace_sleep(handle->hdl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def consume(*types, &block) | |
filter_types(types) | |
@t.buf_consumer(buf_consumer) | |
begin | |
while(true) do | |
@t.sleep # the tricky little trickster | |
work = @t.work(probe_consumer, rec_consumer(block)) | |
if (@done || work > 0) | |
break | |
end |