Skip to content

Instantly share code, notes, and snippets.

@RyanScottLewis
RyanScottLewis / Rakefile
Created May 4, 2011 08:02
Check for bundler
begin
require 'bundler'
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install dependencies"
exit e.status_code
rescue Gem::LoadError => e
$stderr.puts e.message
class Character
class SimpleDSL
def self.call(parent, &blk)
# Create an instance of SimpleDSL
instance = new
# Copy instance variables from the parent to the instance of SimpleDSL
parent.instance_variables.each do |iv|
value = parent.instance_variable_get(iv)
[ryguy@ryguy-fedora ~]$ rvm notes
Notes for Linux ( Fedora release 15 (Lovelock) )
NOTE: 'ruby' represents Matz's Ruby Interpreter (MRI) (1.8.X, 1.9.X)
This is the *original* / standard Ruby Language Interpreter
'ree' represents Ruby Enterprise Edition
'rbx' represents Rubinius
static void *
rb_dl_callback_func_7_8(long arg0, long arg1, long arg2, long arg3, long arg4, long arg5, long arg6, long arg7, long arg8, long arg9, long arg10, long a
@RyanScottLewis
RyanScottLewis / webapp.rb
Created May 27, 2011 05:22
Ironing out details on a new web application library
require 'pp'
# The only thing you're really doing when defining a web aplication is setting
# attributes on your application class.
# For example, the following can be written many ways:
# in ./lib/app.rb
class MyApp < WebApplication
# This method just runs the given files within the scope of your
# application class in the order specified. This also loads the file into
@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 = "[email protected]"
s.description = "helps out with writing your project."
s.summary = "A library helps your project!"
s.require_paths = ["lib"]
@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 / 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 / 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 / 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")