Skip to content

Instantly share code, notes, and snippets.

class Mysql
def incremental_query(query, &block)
result = nil;
def result.free;end
begin
qwr = self.query_with_result
self.query_with_result = false
result = self.query(query).use_result
result.each { |row| yield(row) }
self.query_with_result = qwr
# FileFind.here/:up/:tmp/:reports/'flat.txt'
# FileFind(__FILE__)/:blah/:foo/'baz.bar'
def FileFind(file)
FileFind::FileFinder.new(File.expand_path(File.dirname(file)))
end
module FileFind
def self.at_file(file)
# possibly-better-but-at-least-different version of andand.
# myObject.method.garbage.method.garbage.garbage.garbage.method.method.garbage
# ... works, unlike with the standard andand.
class Object
def andand
AndAnd.new(self)
end
end
def newmethod(candidate, set_arr)
set_arr.each_with_index.inject([]) do |a, v|
a << v[1] if v[0] == candidate
a
end
end
@burke
burke / x.rb
Created January 28, 2010 16:08
irb(main):008:0> block = Proc.new{print "Hello"}
=> #<Proc:0x00000001016f45f8@(irb):8>
irb(main):009:0> new_block = Proc.new{|block| block.call; print ", World!"}
=> #<Proc:0x00000001016e6750@(irb):9>
irb(main):010:0> new_block.call(block)
Hello, World!=> nil
irb(main):011:0>
arr = "thisIsATest\ntest test\nstill testing"
callcc do |cc|
arr.lines.each do |line|
line.each_char do |char|
if char == " "
cc.call
else
print char
class MyModel < ActiveRecord::Base
def self.find_by_name(*args)
super(*args) || raise(ActiveRecord::RecordNotFound)
# What happens here is that occasionally (always, with rspec), super(*args) causes
# the method to return nil immediately, and not evaluate anything else in the method body.
# We've even tried:
# super(*args)
# raise StandardError
# and rspec still just gets nil.
if [[ ! -z "$unicode_flag" ]] ; then
interpreter="$(echo $ruby_string | awk -F'-' '{print $1}')"
version="$(echo $ruby_string | awk -F'-' '{print $2}')"
[[ x$interpreter = xjruby ]] && unicode=""
[[ x$interpreter = xrbx ]] && unicode="☃"
[[ x$interpreter = xree ]] && unicode=""
[[ x$interpreter = xmacruby ]] && unicode=""
[[ x$interpreter = xmaglev ]] && unicode=""
[[ x$interpreter = xironruby ]] && unicode=""
[[ x$interpreter = xmput ]] && unicode=""
From e8391aaebdca619551ab0b1bd5e1b19091728c80 Mon Sep 17 00:00:00 2001
From: Burke Libbey <[email protected]>
Date: Wed, 3 Feb 2010 12:53:57 -0600
Subject: [PATCH] FIXED #methods to return class methods on the class of an instance of a metaclass
---
kernel/common/kernel.rb | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/kernel/common/kernel.rb b/kernel/common/kernel.rb