Skip to content

Instantly share code, notes, and snippets.

t = {"apple", "orange"}
setmetatable(t, {
__index = function (t, i)
t[i] = "absent"
return t[i]
end
})
print(t[3]) -- => "absent"
@amoeba
amoeba / gist:48256
Created January 17, 2009 04:08
Syntax hack to let you use the equals operator on two tables to check if table one is a member of table two
Set = {}
Set.mt = {}
function Set.new(t)
local set = {}
setmetatable(set, Set.mt)
for i,v in ipairs(t) do set[i] = v end
return set
end
require 'prawn'
require 'prawn/layout'
Prawn::Document.generate("table-test.pdf") do
headers = ["Course", "Grade", "Comments"]
data = [["Home Room", "A+", "Great work!"],
["Home Room", "A+", "Great work!"],
["Home Room", "A+", "Great work!"],
["Home Room", "A+", "Great work!"],
["Home Room", "A+", "Great work!"]]
require 'prawn'
require 'prawn/layout'
Prawn::Document.generate("table-test2.pdf") do
headers = ["Course", "Grade", "Comments"]
data = []
10.times { |i| data << ["Home Room", "A+", "Great work!"]}
def make_table(headers, data)
table(
require 'prawn'
Prawn::Document.generate('crop-marks.pdf') do
spacing = 12
margin = 100
canvas do
# topleft corner
stroke_line [bounds.left + spacing, bounds.top - margin],
[bounds.left + margin - spacing, bounds.top - margin]
require 'prawn'
require 'prawn/layout'
Prawn::Document.generate("prawn-table-height.pdf") do
data = [["This is a line"]] * 10
row_height = font.ascender - font.descender + font.line_gap
10.times do |i|
stroke_rectangle([0, bounds.top - (i * row_height)], 100, row_height)
print("You have no mail");
running <- T;
while(running) {
c <- scan(n=1, what="character", quiet=T)
if(c=="uname") {
print("RUnix 1.1")
} else if(c=="halt") {
running <- F
data <- read.csv("birth-data.csv")
data.sorted <- data[do.call(order, data[c("Pair.ID", "Birth.Order")]), ]
tapply(data.sorted$IQ,data.sorted$Pair.ID,function(x){x[2]-x[1]})
We couldn’t find that file to show.
$ ruby -v
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-darwin10.2.0]
$ rails server
/Users/bryce/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `require': /Users/bryce/.rvm/gems/ruby-1.9.1-p378/bundler/gems/right-rails-31e116387439ab0e3214eef55f316e6da35920f3-master/lib/right_rails/helpers/forms.rb:122: invalid multibyte char (US-ASCII) (SyntaxError)
/Users/bryce/.rvm/gems/ruby-1.9.1-p378/bundler/gems/right-rails-31e116387439ab0e3214eef55f316e6da35920f3-master/lib/right_rails/helpers/forms.rb:122: invalid multibyte char (US-ASCII)
/Users/bryce/.rvm/gems/ruby-1.9.1-p378/bundler/gems/right-rails-31e116387439ab0e3214eef55f316e6da35920f3-master/lib/right_rails/helpers/forms.rb:122: syntax error, unexpected $end, expecting '}'
content_tag :div, '★', :class => i < value ? 'ri...
^
from /Users/bryce/.rvm/gems/ruby-1.9.1-p378/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `block in require'