This file contains hidden or 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 'thread' | |
# explicit type for items that we process here | |
Item = Struct.new :name, :sha1, :meta | |
# dummies | |
def sha1(x) x.hash end | |
def update_metadata(it) it.meta = Time.now end | |
# |
This file contains hidden or 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 MultiDimensionalArray | |
def self.[](*dimension_sizes) | |
new(*dimension_sizes) | |
end | |
def self.cube(dimensions, dimension_size) | |
new(*Array.new(dimensions, dimension_size)) | |
end | |
def initialize(*dimension_sizes) |
This file contains hidden or 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 'set' | |
LOCK = Mutex.new | |
num = Integer(ARGV.shift || 4) | |
processes = Set.new | |
Signal.trap "INT" do |s| | |
$stderr.puts "Shutdown" |
This file contains hidden or 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
package generics2; | |
import java.util.SortedSet; | |
import java.util.TreeSet; | |
/** | |
* Base comparable class with "type self consciousness". | |
*/ | |
class BaseC implements Comparable<BaseC> { |
This file contains hidden or 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
irb(main):032:0> s="x(a(b)()c)y" | |
=> "x(a(b)()c)y" | |
irb(main):033:0> %r{(?<ne> \( (?:\g<ne>|[^()]+)* \) )}x.match s | |
=> #<MatchData "(a(b)()c)" ne:"(a(b)()c)"> | |
irb(main):034:0> s = "f_(a)(x)=x^(2)+(5x//f'(x))" | |
=> "f_(a)(x)=x^(2)+(5x//f'(x))" | |
irb(main):045:0> s.scan %r{(?<ne> \( (?: \g<ne> | [^()] )* \) )}x | |
=> [["(a)"], ["(x)"], ["(2)"], ["(5x//f'(x))"]] |
This file contains hidden or 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
public final class PropVsMeth { | |
/** We use boolean properties. */ | |
public enum Prop { | |
A(true, true), B(true, false), C(false, true); | |
private final boolean a; | |
private final boolean b; |
This file contains hidden or 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 'optparse' | |
first = last = nil | |
OptionParser.new do |opts| | |
opts.on '-s', '--start=LINE', Integer, 'Start line' do |v| | |
first = v | |
end | |
opts.on '-e', '--end=LINE', Integer, 'End line' do |v| |
This file contains hidden or 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 'benchmark' | |
REP = 10 | |
Benchmark.bm 20 do |x| | |
pixels = Array.new(258000, rand(256)).freeze | |
old_lv = nil |
This file contains hidden or 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
package clj; | |
import java.util.HashSet; | |
import java.util.Set; | |
/** | |
* Example code. | |
* | |
* @author rklemme | |
* @see <a href="https://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/295e9e9fb6b3e489">comp.lang.java.programmer</a> |
This file contains hidden or 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 Enum | |
module EnumMember | |
attr_reader :args | |
def [](idx) | |
args[idx] | |
end | |
end | |
class <<self |