Skip to content

Instantly share code, notes, and snippets.

@epitron
epitron / frozen_stuff.rb
Created November 10, 2008 13:38 — forked from Sutto/frozen_stuff.rb
undefined
require 'rubygems'
# Only load paths from the folder 'gems' under the current
# dir - e.g. ./gems/
# To freeze use gem install <name> -i gems
Gem.clear_paths
File dsl
Gem.path.unshift (PWD / 'gems').absolute_path
end
config.gem "rspec", :lib => false
config.gem "rspec-rails", :lib => false
config.gem "cucumber", :lib => false
config.gem "thoughtbot-factory_girl", :lib => false, :source => "http://gems.github.com"
config.gem "faker", :lib => false
config.gem "carlosbrando-remarkable", :lib => "remarkable", :source => "http://gems.github.com"
config.gem "haml"
config.gem "webrat"
config.gem "htmlentities"
config.gem "json"
require 'benchmark'
bigstring = "bigstring" * 100
n = 1000000
Benchmark.bm do |x|
x.report("<<") { n.times { bigstring.dup << bigstring << bigstring } }
x.report("+") { n.times { bigstring + bigstring + bigstring } }
end
@epitron
epitron / 1_smtpd.rb
Created January 4, 2009 03:29
A 77 line SMTP server, and a 253 line POP3 server.
require 'gserver'
require 'rubygems'
require 'active_record'
dbconfig = YAML::load_file(File.dirname(__FILE__) + '/config/database.yml')
ActiveRecord::Base.establish_connection(dbconfig['development'])
# CREATE TABLE emails (id integer primary key autoincrement, mail_from, rcpt_to, subject, email, user_id integer);
# CREATE TABLE users (id integer primary key autoincrement, username, password, email);
$ time ruby1.8 bits.rb 16 > /dev/null
real 0m9.861s
user 0m8.977s
sys 0m0.872s
$ time ruby1.9 bits.rb 16 > /dev/null
real 0m1.742s
user 0m1.740s
#---------------------------------------------------------------------------
# The first one receives and prints a datagram:
#---------------------------------------------------------------------------
require 'rubygems'
require 'eventmachine'
module A
def receive_data a
p a
#!/usr/bin/env ruby1.9
class Array
def powerset
# the bit pattern of the numbers from 0...2^(num_elements) can be used to select the elements of the set...
(0...2**size).map do |bitmask|
select.with_index{ |e, i| bitmask[i] == 1 }
end
end
@epitron
epitron / streamed_zip.rb
Last active September 4, 2015 14:25
A Ruby class for compressing and streaming ZIP files on the fly.
require 'epitools'
class StreamedZip
## TODO: Use arrays instead of string munging, then join results. (Wrapper class! (Pathname?))
def initialize(paths)
@paths = paths
end
def stream(opts={}, &block)
require 'progressbar'
class Mechanize
class Chain
class ResponseReader
def handle(ctx, params)
params[:response] = @response
body = StringIO.new
total = 0
diff --git a/lib/autotest/rails_rspec.rb b/lib/autotest/rails_rspec.rb
index 2aa4f5f..df7f4cf 100644
--- a/lib/autotest/rails_rspec.rb
+++ b/lib/autotest/rails_rspec.rb
@@ -25,6 +25,11 @@ $:.push(*Dir["vendor/rails/*/lib"])
require 'active_support'
require 'autotest/rspec'
+Autotest.add_hook :died do |at, err|
+ puts "Died! Error: #{err.inspect}"