Skip to content

Instantly share code, notes, and snippets.

<table class="ages">
<tr class="person"><td class="name">John</td><td class="age">24</td></tr>
<tr class="person"><td class="name">Dean</td><td class="age">30</td></tr>
</table>
<div class="ages">
<div class="person"><div class="name">John</div><div class="age">24</div></div>
<div class="person"><div class="name">Dean</div><div class="age">30</div></div>
</div>
.ages { display: table; }
.person { display: table-row; }
.name { display: table-cell; }
.age { display: table-cell; }
@trans
trans / tigerops-ages-xml.html
Created February 11, 2009 00:44
XML/CSS Example
<ages>
<person><name>John</name><age>24</age></person>
<person><name>Dean</name><age>30</age></person>
</ages>
ages { display: table; }
person { display: table-row; }
name { display: table-cell; }
age { display: table-cell; }
@trans
trans / yamlstruct.rb
Created June 24, 2009 09:22
YAMLStruct
# Turn a YAML document into an object via method_missing delegation.
# This is a pretty useless idea since you can just use OpenStruct.
#
# OpenStruct.new(YAML.load(yaml))
#
class YAMLStruct < BasicObject
def initialize( stream )
@yaml = YAML::load( stream )
end
@trans
trans / shadow_method.rb
Created June 24, 2009 09:29
Shadow Method
# Quickly create shadow methods, eg. #__foo__ from #foo.
# This has a very limited use case, just use alias_method instead.
class Module
# Define a shadow alias for a method.
#
# class X
# shadow_method( :class )
# end
@trans
trans / fixnum_constants.rb
Created June 24, 2009 09:34
Fixnum Constants
# Fixnum Constants
# Constants providing the numerical limitations of Fixnum class.
#
class Fixnum
N_BYTES = [42].pack('i').size
N_BITS = N_BYTES * 8
MAX = 2 ** (N_BITS - 2) - 1
MIN = -MAX - 1
end
@trans
trans / filefetch.rb
Created June 24, 2009 09:44
Fetch File from Disk or Web
# This is the first reusable ruby lib I ever wrote.
# It is pretty useless now, and in hindsight not so well
# written either, but I've gist it for posterity.
# TomsLib - Tom's Ruby Support Library
# Copyright (c) 2002 Thomas Sawyer, LGPL
#
# FetchFile
#
# For purposes of this library a url is defined as both
@trans
trans / binding_of_caller.rb
Created June 24, 2009 09:48
Binding of Caller
# Binding-of-Caller, Copyright (c) 2003 Florian Gross
# (No longer works with Ruby after version 1.8+)
class Continuation; end # :nodoc: # for RDoc
def Continuation.create(*args, &block) # :nodoc:
cc = nil; result = callcc {|c| cc = c; block.call(cc) if block and args.empty?}
result ||= args
return *[cc, *result]
end
end
@trans
trans / enumtype.rb
Created June 24, 2009 10:52
EnumeratedType (define numerical constants quickly)
# EnumeratedType lets you create enumerated types like this:
#
# class OutputType < EnumeratedType
# AUTODETECT
# UNKNOWN
# NOSOUND
# WAVWRITER
# DSOUND
# WINMM
# ASIO
@trans
trans / gem_extensions.rb
Created June 24, 2009 11:24
Gem.active?
# Gem.active?, Gem.gemspec and Gem.gempath.
# These are RubyGems extensions I created a while back.
# I'm not sure how relevant they are any longer however.
# Does RubyGems now have other means to do these?
module Gem
def self.active?(gemname)
@loaded_specs ||= Hash.new
@loaded_specs.key? gemname