Skip to content

Instantly share code, notes, and snippets.

@bigcurl
bigcurl / app.rb
Created April 8, 2009 14:35
Bringing up a Sinatra app. Thanks to Ola Bini for the split script.
require 'rubygems'
require 'sinatra'
get '/' do
"Hello from Sinatra running on Java!"
end
@bigcurl
bigcurl / sha_stream.rb
Created May 14, 2011 15:25
A simple goliath API that is supposed to take the hash of an uploaded stream.
#!/usr/bin/env ruby
# encoding: utf-8
require 'goliath'
require 'digest/sha1'
class ShaStream < Goliath::API
# use Goliath::Rack::Params
def on_headers(env, headers)
@bigcurl
bigcurl / sha_stream.rb
Created May 16, 2011 21:27
A simple goliath API that returns the sha1 hash of an uploaded file.
#!/usr/bin/env ruby
# encoding: utf-8
require 'goliath'
require 'digest/sha1'
class ShaStream < Goliath::API
def on_headers(env, headers)
env['async-digest'] = Digest::SHA1.new # SHA1 or MD5
str = env['CONTENT_TYPE'].match(/multipart\/form-data.*boundary\=?([^"\;,]+)?/)
@bigcurl
bigcurl / upload.rb
Created May 17, 2011 10:51
Upload a file to a webserver via socket
require 'thread'
require 'net/http'
require 'base64'
require 'openssl'
class Producer
def initialize
@mutex = Mutex.new
@body = ''
end
@bigcurl
bigcurl / sha_stream.rb
Created May 18, 2011 06:10
CPU spikes while copying data to a socket.
#!/usr/bin/env ruby
# encoding: utf-8
require 'goliath'
require 'digest/sha1'
class ShaStream < Goliath::API
def on_headers(env, headers)
env['async-digest'] = Digest::SHA1.new # SHA1 or MD5
str = env['CONTENT_TYPE'].match(/multipart\/form-data.*boundary\=?([^"\;,]+)?/)