Skip to content

Instantly share code, notes, and snippets.

View ecin's full-sized avatar
🐶
Woof!

ecin ecin

🐶
Woof!
View GitHub Profile
@ecin
ecin / search.rb
Created October 28, 2010 14:45
Search model for system-wide searching with Texticle.
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'
# 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
require 'rack'
require 'rack/builder'
require 'rack/lobster'
class MagLevTransactionWrapper
def initialize(app)
@app = app
end
def call(env)
config.gem 'rack-probe'
config.middleware.use 'Rack::Probe'
// 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 /
// 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);
# 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
#!/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
/*
* 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);
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