Skip to content

Instantly share code, notes, and snippets.

require "threaded_collections"
threadcount = 2
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
tps = ThreadedCollectionProcessor.new(arr)
tps.process(2) { |thread_id, item| puts "Thread #{thread_id} processed item: #{item}" }
# From Edge Rails
class Object
unless public_method_defined?(:present?)
def present?
!blank?
end
end
end
string[] ids = this.Parameters["OrderByRank"].Split(',');
for (int x = 0; x < ids.Length; x++)
{
Event foundevent = ec.Find(delegate(Event e)
{
return e.ViewID == ids[x];
});
if (foundevent != null)
foundevent.Order = -1000 + x; // start at -1000 because the default order is 0
}
require 'benchmark'
TIMES = 10_000_000
:foo # Anal-retentivity
def thrice_yield
3.times { yield }
end
def thrice_block &block
3.times &block
@tamalw
tamalw / tweet_beat.rb
Created July 25, 2008 22:10
Watch your keywords appear on the twitter stream
#
# tweet_beat.rb
# ShoesFest 2008
#
# Created by Tamal White on 2008-07-25.
# Copyright 2008 Tamal White. All rights reserved.
#
require 'hpricot'
@-moz-document domain("github.com") {
.userbox {
position: absolute;
right: 10px;
}
}
Once upon a time a goat travelled happily through a green pasture
Once upon a time it suddenly decided to flip backwards, and there went Time
def parse(x)
$joined = 0
$counter = 0
# INITIALIZE VARIABLES
upmynick = $irc_nick
mynick = upmynick.downcase
nick = ""
chan = ""
require 'logger'
log = Logger.new(STDOUT)
threads = []
10.times do
threads << Thread.new do
loop do
log.info("foo")