Skip to content

Instantly share code, notes, and snippets.

Sam Goldman samwgoldman

View GitHub Profile
@samwgoldman
samwgoldman / request.json
Last active Aug 29, 2015
Example of nested errors in JSON
View request.json
{
"object": {
"groups": [
{
"options": [
{
},
{
}
],
View gist:9610193
access_key_id = ENV.fetch("APP_S3_ACCESS_KEY_ID")
secret_access_key = ENV.fetch("APP_S3_SECRET_ACCESS_KEY")
bucket_name = ENV.fetch("APP_S3_BUCKET")
s3 = AWS::S3.new(access_key_id: access_key_id, secret_access_key: secret_access_key)
bucket = s3.buckets[bucket_name]
object = bucket.objects["whatever/you/want"]
presign = AWS::S3::PresignV4.new(object)
presign.presign(:put, expires: 15.minutes.from_now.to_i)
# => #<URI::HTTP:0x007fcfcd97e1a0 URL:***stuff***>
View result.rb
module Result
class << self
def not_nil(value)
if value.nil?
None
else
Some.new(value)
end
end
@samwgoldman
samwgoldman / main.rb
Last active Aug 29, 2015
TorqueBox testing issue
View main.rb
require "capybara"
require "capybara/poltergeist"
require "torquebox-web"
require "torquebox-messaging"
page = DATA.read
app = proc do
headers = {
"Content-Type" => "text/html",
"Content-Length" => page.length.to_s
@samwgoldman
samwgoldman / result.rb
Last active Aug 29, 2015
success/failure result object
View result.rb
module Result
class << self
def success(value)
Success.new(value)
end
def failure(error)
Failure.new(error)
end
end
View cyclic.js
var foo = {}
Object.defineProperty(foo, "bar", {
enumerable: true,
get: function() {
return bar;
}
})
var bar = { foo: foo }
foo.bar.foo === foo // true
View gist:868311
class Hash
def each_recursive(&block)
self.each do |k, v|
yield k, v
v.each_recursive(&block) if v.is_a?(Hash)
end
end
def each_key_recursive(&block)
self.each_recursive { |k, _| yield k }
@samwgoldman
samwgoldman / gist:1131386
Created Aug 8, 2011
Ruby method that builds XPath which finds fields within tables as labeled by the table headers
View gist:1131386
# 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
@samwgoldman
samwgoldman / gist:1199827
Created Sep 7, 2011
Create an html table with shorthand syntax
View gist:1199827
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:1579739
Created Jan 8, 2012
Theano nosetests results on aws cg1.4xlarge nvidia M2050. floatX=float32, device=GPU
View gist:1579739
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
You can’t perform that action at this time.