Skip to content

Instantly share code, notes, and snippets.

@Pistos
Pistos / permutations.rb
Created April 16, 2009 13:49
Off-the-top-of-my-head implementation of array permutation.
class Array
def perms
return [ self ] if size < 2
map { |e|
( self - [ e ] ).perms.map { |p| [ e ] + p }
}.flatten( 1 )
end
end
p [ 'a', 'b', 'f', [ 1,2 ] ].perms
@Pistos
Pistos / start.rb
Created April 30, 2009 19:09
Ramaze Example: Using render_view for nested partials.
require 'rubygems'
gem 'ramaze', '2009.04'
require 'ramaze'
class MainController < Ramaze::Controller
map '/'
def index
@message = "Hello!"
end
@Pistos
Pistos / bench.rb
Created June 2, 2009 05:13
Etanni vs. ERb
ETANNI_TEMPLATES = {}
ETANNI_TEMPLATES[:simple] = <<'T'
<h1>Nothing here</h1>
T
ETANNI_TEMPLATES[:small] = <<'T'
<?r 100.times do |n| ?>
#{n}
<?r end ?>
@template = %q{
<div class="#{html_class}">
<h3>#{capitalized_title}</h3>
<table>
#{trs}
</table>
<h3>#{title}</h3>
</div>
}
@Pistos
Pistos / gist:142412
Created July 7, 2009 22:17
Diff of Diakonos from 0.8.10 to 0.8.11
diff --git a/CHANGELOG b/CHANGELOG
index 335e9b9..de6228d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,8 +1,22 @@
Diakonos Changelog
------------------
+0.8.11
+
# DBI::Row.new(columns, column_types, size_or_array=nil)
#
# Returns a new DBI::Row object using +columns+. The +size_or_array+
# argument may either be an Integer or an Array. If it is not provided,
# it defaults to the length of +columns+.
#
# Column types is a corresponding Array of Class/Module objects that
# conform to the DBI::Type interface. These will be used to convert types
# as they are returned.
#
@Pistos
Pistos / gist:177395
Created August 29, 2009 05:14
Passing accessors to children
We couldn’t find that file to show.
require 'better-benchmark'
r1 = Regexp.new( 'a' )
r2 = /a/
s = 'a'
puts 'Regexp.new vs. /regexp/'
result = Benchmark.compare_realtime(
:iterations => 10,
require 'better-benchmark'
b = 'b'
r = /a#{b}/
s = 'ab'
puts "Precreated interpolated vs. not precreated interpolated"
result = Benchmark.compare_realtime(
:iterations => 10,
Letters drawn with straight lines, followed by letters with curves. :) (Answer to http://friendfeed.com/pistos/e5d8bc50/my-6-year-old-asked-daddy-can-you-guess-sorting )