Skip to content

Instantly share code, notes, and snippets.

US East (Northern Virginia) Region
Amazon EC2 running Linux/UNIX
$0.34 per Large Instance (m1.large) instance-hour (or partial hour) 81 Hrs 27.54
Amazon EC2 EBS
$0.10 per GB-month of provisioned storage 0.860 GB-Mo 0.09
$0.10 per 1 million I/O requests 730,931 IOs 0.07
@RyanScottLewis
RyanScottLewis / user_dsl.rb
Created December 8, 2011 19:11
Simple User Dsl
class User
class DSL
def self.dsl_attr_accessor (*names)
names.each do |name|
name = name.to_sym
define_method(name) do |value=nil|
@result[name] = value unless value.nil?
@result[name]
$ cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git@github.com:SomePerson/SomeProject.git master"
command finished in 1280ms
* executing "if [ -d $HOME/sites/some_project/shared/cached-copy ]; then cd $HOME/sites/some_project/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard c06a130a7a20364a5de5c0bdbaa4bdec8c5f2519 && git clean -d -x -f; else git clone git@github.com:SomePerson/SomeProject.git $HOME/sites/some_project/shared/cached-copy && cd $HOME/sites/some_project/shared/cached-copy && git checkout -b deploy c06a130a7a20364a5de5c0bdbaa4bdec8c5f2519; fi"
Thanks for the pull request! Before I can pull it though, two things need changed:
Tests! A lot of people are using MongoMapper, so we want to make sure we don't break this in the future.
I don't like manually deleting the options for the connection string. What do you think about having driving options nested with the other connection settings? Something like:
MongoMapper.config = {'development' => {:port => 12345, :options => {:pool_size => 5}}
inflect.plural /^(movie_data)$/, '\1'
inflect.singular /^(movie_data)$/, '\1'
@RyanScottLewis
RyanScottLewis / gist:1254207
Created September 30, 2011 16:00
Finding spec stuff and blah
puts Dir.glob("spec/**/*_spec.rb").inject([]) { |memo, spec_file|
spec_file = Pathname.new(spec_file)
memo << "#{spec_file} is missing the encoding at the top" if spec_file.read !~ /encoding/
memo
}.join("\n")
@RyanScottLewis
RyanScottLewis / missing_spec_source.rb
Created September 12, 2011 17:16
Missing spec/source files within Rails apps
def all_spec_files_with_missing_source_files
spec_source_hash = Dir.glob("spec/**/*_spec.rb").inject({}) do |memo, spec_file|
memo[spec_file] = spec_file.gsub(/^spec/, 'app').gsub(/_spec\.rb$/, '.rb')
memo
end
spec_source_hash.find_all { |spec_file, source_file| !File.exists?(source_file) }.collect(&:first)
end
@RyanScottLewis
RyanScottLewis / README.md
Created September 1, 2011 23:40
Benchmarking require calls..
  1. Modify the boot.rb file in your Rails application to reflect the one above.
  2. Run rails s
  3. Select all of the lines that include the following format: (000000.0) foobar required
  4. Copy those lines, open TextMate and paste into a /new/ document.
  5. Press F5 then press 1 to sort all lines in the document.

You can now tell which libraries/files take the longest to load.

@RyanScottLewis
RyanScottLewis / gist:1132791
Created August 8, 2011 21:25
read_nonblock_ruby_19.rb
# This fix is needed to preform GET/POST/PUT/DELETE requests to HTTPS
if RUBY_ENGINE == "jruby" && RUBY_VERSION == "1.9.2"
Net::BufferedIO.class_eval do
BUFSIZE = 1024 * 16
def rbuf_fill
timeout(@read_timeout) do
@rbuf << @io.sysread(BUFSIZE)
end
@RyanScottLewis
RyanScottLewis / proj.gemspec
Created May 29, 2011 06:48
The self-generating, completely amazing, edit and forget it... gemspec!
#!/bin/ruby
Gem::Specification.new do |s|
s.author = "John Doe"
s.email = "j.doe@email.com"
s.description = "helps out with writing your project."
s.summary = "A library helps your project!"
s.require_paths = ["lib"]