This file contains hidden or 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 '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 |
This file contains hidden or 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
| 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. |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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" |
This file contains hidden or 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 Methodize | |
| def method_missing(sym, *args, &block) | |
| self.class.class_eval do | |
| define_method(sym) { args.first } | |
| end | |
| end | |
| end | |
| __END__ | |
| module A |
This file contains hidden or 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 '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' |
This file contains hidden or 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
| { | |
| "album": [{ | |
| "id": null, | |
| "name": null, | |
| "track": [{ | |
| "name": null, | |
| "index": null, | |
| "sort": "index" | |
| }], | |
| "release_date": null, |
This file contains hidden or 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
| class A | |
| def inspect | |
| 'hi' | |
| end | |
| end | |
| a = A.new | |
| puts a.inspect | |
| puts Object.instance_method(:inspect).bind(a).call |
This file contains hidden or 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
| 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"); |
This file contains hidden or 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
| 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. |