This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Rack | |
# Bounces or redirects requests to missing static files. | |
# Partially inspired by [http://menendez.com/blog/using-django-as-pass-through-image-proxy/](http://menendez.com/blog/using-django-as-pass-through-image-proxy/) | |
# | |
# I.e. could be useful when you want to run the server with production database locally | |
# and have user uploaded content fetched transparently from production site. | |
# | |
# Options: | |
# :mode - [ :off, | |
# :bounce, # returns 404 to any request to static URL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check Thomas Sawyer take on the problem http://github.com/rubyworks/paramix | |
module IncludableWithOptions | |
class << self | |
attr_accessor :last_default_options | |
end | |
def self.included(includable_with_options) | |
%w(string/methodize kernel/constant module/basename module/spacename).each { |facets_core_ext| require "facets/#{ facets_core_ext }" } | |
raise "IncludableWithOptions should be included by the Module" unless includable_with_options.instance_of?(Module) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TryBlock | |
def self.install! | |
unless Object.include?(self) | |
Object.send(:include, self) | |
Object.send(:public, :try_block) | |
end | |
end | |
def self.is_nil_exception_message?(message) | |
message =~ /You have a nil object when you didn't expect it/ || |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Safe way to intercept IO stream | |
# where just replacing STDOUT doesn't work: | |
# http://rubyforge.org/tracker/index.php?func=detail&aid=5217&group_id=426&atid=1698 | |
# | |
module IoInterceptor | |
def intercept | |
begin | |
@intercept = true | |
@intercepted = "" | |
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ## ShellOut | |
# | |
# Provides a convenient feature-rich way to "shell out" to external commands. | |
# Most useful features come from using `PTY` to execute the command. Not available | |
# on Windows, `Kernel#system` will be used instead. | |
# | |
# ## Features | |
# | |
# ### Interruption | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "net/http" | |
Net::HTTP.module_eval do | |
def D(msg) | |
(@debug_output ||= STDERR) << msg << "\n" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Usage: ./gist_readme.rb source_file.rb [README.md] | |
# | |
# Extracts first comment block from source_file.rb into README.md file | |
# | |
# | |
raise "source_file should be specified" if ARGV.empty? | |
File.open(File.expand_path(File.join("../", ARGV[1] || "README.md") , __FILE__), "w") do |f| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RequireGistTestGist = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Formats the Exception so that it looks *familiar*, | |
# i.e. exactly like your interpreter does it. | |
# | |
# Port of MRI native `error_print` function. | |
class Exception | |
def self.error_print(e) | |
warn_print = "" | |
backtrace = e.backtrace | |
backtrace = [ backtrace ] if backtrace.is_a?(String) # 1.9 returns single String for SystemStackError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def without_block_arg | |
if defined?(yield) | |
yield(42) | |
else | |
# no block passed | |
end | |
end | |
def with_block_arg(&block) | |
if block |