Skip to content

Instantly share code, notes, and snippets.

View sandro's full-sized avatar
☀️
Sharing Goodness

Sandro Turriate sandro

☀️
Sharing Goodness
View GitHub Profile
require 'benchmark'
n = 50000
# s = ""
# when 's' is global the benchmark runs much slower
Benchmark.bmbm do |x|
x.report("+=") do
s = ""
n.times { s += "." }
end
@sandro
sandro / Rails load order.txt
Created July 22, 2009 17:43
Rails 2 loading order
Loading development environment (Rails 2.2.2)
config/environment.rb inside of Rails::Initializer.run block
config/environments/development.rb
vendor/plugins/
config/initializers
config/environment.rb inside of config.after_initialize block
gems in GEM_PATHS
lib/
Constants in lib/ are autoloaded when the constant is missing.
should "allow deeply nested many associations" do
Address.class_eval do
many :people
end
person = Person.new :name => 'Meg'
address = Address.new :state => 'FL'
address.people << person
project = Project.new
project.addresses << address
@sandro
sandro / README
Created July 9, 2009 21:50
fork a long running process
Spawn a long-running process in response to a POST request. The
request spawns a child and immediately redirects, making the request
non-blocking. The child changes the text on the index page from
"Running" to "Not running" after finishing its work.
Instructions:
ruby app.rb
visit http://localhost:4567
push "Run"
notice the text says "Running"
module Methodize
def method_missing(sym, *args, &block)
self.class.class_eval do
define_method(sym) { args.first }
end
end
end
__END__
module A
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.spec_files = FileList['spec/**/*_spec.rb']
end
Spec::Rake::SpecTask.new(:rcov) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
{
"album": [{
"id": null,
"name": null,
"track": [{
"name": null,
"index": null,
"sort": "index"
}],
"release_date": null,
class A
def inspect
'hi'
end
end
a = A.new
puts a.inspect
puts Object.instance_method(:inspect).bind(a).call
html = html.Replace("://", ":~~");
if ((ConfigurationManager.AppSettings.Get("RemoveWhitespaceMode") + string.Empty).Equals("Insane", StringComparison.OrdinalIgnoreCase))
{
html = Regex.Replace(html, @"(\/\*(\s*|.*?)*\*\/)|(\/\/.*)", String.Empty); // remove javascript comments
html = Regex.Replace(html, @"(?<=[^])\t{2,}|(?<=[>])\s{2,}(?=[<])|(?<=[>])\s{2,11}(?=[<])|(?=[\n])\s{2,}", string.Empty);
html = Regex.Replace(html, @"[ \f\r\t\v]?([\n\xFE\xFF/{}[\];,<>*%&|^!~?:=])[\f\r\t\v]?", "$1");
proxybot
Wanted to capture the code flying around in my head and
thought a bot would be the best way to describe it.
A bot has a set of actions it knows how to perform. It
also needs to be able to perform any of its actions
when an event occurs. This gist attempts to solve this
problem through a type of proxy thing.