Handy resource for keywords: http://ruby-doc.org/docs/keywords/1.9/
This doc: http://bit.ly/1EqHNPH
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' | |
# NOTE: test passes on 4.1.13, fails against 4.2.0+ |
Handy resource for keywords: http://ruby-doc.org/docs/keywords/1.9/
This doc: http://bit.ly/1EqHNPH
Parent Load (0.1ms) SELECT "parents".* FROM "parents" WHERE "parents"."id" = ? LIMIT 1 [["id", 1]] | |
(0.0ms) begin transaction | |
SQL (0.0ms) INSERT INTO "students" DEFAULT VALUES | |
SQL (0.0ms) INSERT INTO "student_parents" ("parent_id", "student_id") VALUES (?, ?) [["parent_id", 1], ["student_id", 1]] | |
(0.0ms) commit transaction |
I hereby claim:
To claim this, I am signing this object:
require 'bigdecimal' | |
def to_decimal(digits, dp) | |
digits = digits.dup | |
if dp < -digits.length | |
digits.unshift(*([nil]*(-digits.length-dp))) | |
end | |
digits.insert(dp+digits.length, '.').map { |x| x || '0' }.join | |
end |
Inspired by Postgres: The Bits You Haven't Found:
\set n 1000;
SELECT 4*COUNT(DISTINCT(x, y))/(1.0*:n*:n) AS result FROM generate_series(0,:n) AS x, generate_series(0,:n) AS y WHERE x*x + y*y <= :n*:n;
This uses the simple method of checking every integer-valued point in [0,n] x [0,n]
to see if it's inside the circle - the Wikipedia approximations to pi article has more details.
require 'benchmark' | |
nelements = 10 | |
nlines = 10 | |
def repeating_string(base, elements, lines) | |
(([base]*elements).join(',')+"\n")*lines | |
end | |
# test string |
GC.start | |
first_count = ObjectSpace.each_object(String) { |x| nil } | |
def dummy_function | |
'foo' | |
end | |
second_count = ObjectSpace.each_object(String) { |x| nil } | |
GC.start | |
second_after_gc_count = ObjectSpace.each_object(String) { |x| nil } |
<def tag="tabs"> | |
<set-scoped tab-names="&[]" tab-contents="&{}"> | |
<ul class="tabs" merge> | |
<do param="default" /> | |
</ul> | |
<do repeat="&scope.tab_names"> | |
<div id="#{this}"> | |
<%= scope.tab_contents[this] %> | |
</div> | |
</do> |
<def tag="page" attrs="title, full-title"> | |
<% full_title ||= "#{title} : #{app_name}" %> | |
<html merge-attrs> | |
<head param> | |
<title param><%= strip_tags full_title %></title> | |
<stylesheet name="reset" /> | |
<do param="scripts"> | |
<javascript param name="prototype, effects, dragdrop, controls, lowpro, hobo-rapid"/> | |
<if-ie version="lt IE 7" param="fix-ie6"> |