Skip to content

Instantly share code, notes, and snippets.

View samwgoldman's full-sized avatar

Sam Goldman samwgoldman

View GitHub Profile
@samwgoldman
samwgoldman / html_builder_example.rb
Created May 23, 2012 17:38
Using smartlogic/html_builder
require "html"
require "html/list"
require "html/map"
module HTML
class Article < Struct.new(:article)
def to_html
HTML.build(article) do |article|
tag(:article, tag(:h2, article.title) + map(:section, article.sections), id: article.id)
end
@samwgoldman
samwgoldman / test.rb
Created April 27, 2012 21:13
webmachine-ruby chunked response with rack adapter streaming
require "webmachine"
require "webmachine/adapters/rack"
class TestResource < Webmachine::Resource
def to_html
parts = %w{Hello, World!}
Fiber.new do
parts.each do |part|
Fiber.yield part
sleep 0.5
@samwgoldman
samwgoldman / $stdout
Created February 18, 2012 09:29
activerecord bug?
active record
role built from a context
context
should eq #<Context id: 1, type: nil>
role built from a role through context
context
should eq #<Context id: 2, type: nil> (FAILED - 1)
student built from a program
program
should eq #<Program id: 3, type: "Program">
class Tests
extend Process
def self.passing?
fork do
begin
require "rspec/autorun"
Dir["spec/**/*_spec.rb"].each do |spec|
require_relative spec
end
@samwgoldman
samwgoldman / gist:1714534
Created February 1, 2012 02:07
first stab at a webmachine-ruby resource def'n
require 'evaluation'
class EvaluationsResource < Webmachine::Resource
class << self
alias_method :let, :define_method
end
let(:allowed_methods) { ["GET", "POST"] }
let(:content_types_provided) { [["application/json", :to_json]] }
let(:content_types_accepted) { [["application/json", :from_json]] }
@samwgoldman
samwgoldman / gist:1580228
Created January 9, 2012 00:15
Theano test results on cg1.4xlarge using ami-12b6477b
[root@master Theano]# python2.6 setup.py develop
running develop
install_dir /usr/lib/python2.6/site-packages/
running egg_info
creating Theano.egg-info
writing requirements to Theano.egg-info/requires.txt
writing Theano.egg-info/PKG-INFO
writing top-level names to Theano.egg-info/top_level.txt
writing dependency_links to Theano.egg-info/dependency_links.txt
writing requirements to Theano.egg-info/requires.txt
@samwgoldman
samwgoldman / gist:1579854
Created January 8, 2012 21:57
Theano nose tests results on was cg1.4xlarge. default config
root@master:~/Theano# nosetests
.E.................................E.......E...E..EEE...........................E....E................................................E..E.....EEEE..........................................E...........................................................SS..E..F........................................................................E...........E.......................................E...../usr/lib/python2.7/dist-packages/scipy/signal/signaltools.py:408: ComplexWarning: Casting complex values to real discards the imaginary part
return sigtools._convolve2d(in1,in2,1,val,bval,fillvalue)
.......................................EEEEEEEEEEE...........................EE...........................E.EE.........E..........................WARNING (theano.gof.cmodule): Cache leak due to unpickle-able key data set([(((3, (3,), (3,), (3,), (3,), (3,)), (10, '1.5.1'), (10, '1.5.1'), (10, '1.5.1'), (10, '1.5.1'), (10, '1.5.1'), (10, '1.5.1')), ('CLinker.cmodule_key', ('-O3', '-Wno-write-strings',
@samwgoldman
samwgoldman / gist:1579739
Created January 8, 2012 21:21
Theano nosetests results on aws cg1.4xlarge nvidia M2050. floatX=float32, device=GPU
root@master:~/Theano# git rev-list HEAD | head -1
c6fc9734f1602bbbb9335bd61e49872b1635b3de
root@master:~/Theano# THEANO_FLAGS='device=gpu,floatX=float32,force_device=True' nosetests
Using gpu device 0: Tesla M2050
...................................E...........E..EEE...........................E....E..................................FF...................................................................E...........................................................SS..E..F................................................................................................................................../usr/lib/python2.7/dist-packages/scipy/signal/signaltools.py:408: ComplexWarning: Casting complex values to real discards the imaginary part
return sigtools._convolve2d(in1,in2,1,val,bval,fillvalue)
.......................................EEEEEEEEEEE...........................EE.F...........................E..................................WARNING: unused streams above 512 (Tune GPU_mrg get_n_streams)
...WARNING (thea
@samwgoldman
samwgoldman / gist:1199827
Created September 7, 2011 05:23
Create an html table with shorthand syntax
def html_table(tableish)
unless tableish.map(&:size).uniq.count == 1
raise 'Must be array of arrays of equal length'
end
table = Nokogiri::HTML::DocumentFragment.parse ''
Nokogiri::HTML::Builder.with(table) { |html|
html.table {
if tableish.first.size > 1
@samwgoldman
samwgoldman / gist:1131386
Created August 8, 2011 08:06
Ruby method that builds XPath which finds fields within tables as labeled by the table headers
# Only works with column oriented tables
# Doesn't support colspan
def tabular_field(locator)
preceding_cells = 'count(ancestor::td[1]/preceding-sibling::td)'
preceding_headers = "count(ancestor::table[1]/thead/th[normalize-space(.) = '#{locator}']/preceding-sibling::th)"
".//input[#{preceding_cells} = #{preceding_headers}]"
end