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 ActionController::Assertions::SelectorAssertions | |
protected | |
# actionpack/lib/action_controller/assertions/selector_assertions.rb | |
jquery_var = ActionView::Helpers::PrototypeHelper::JQUERY_VAR | |
RJS_STATEMENTS[:replace_html] = "#{jquery_var}\\(#{RJS_ANY_ID}\\)\\.html\\(#{RJS_PATTERN_HTML}\\)" | |
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
function do_it(){ | |
var live_query_src = 'http://github.com/brandonaaron/livequery/raw/e634549f1e13b5418fb8d75572866846a332ec8d/jquery.livequery.js'; | |
jQuery.getScript(live_query_src, function(){ | |
jQuery('textarea').livequery(function(){jQuery(this).attr('rows', 20)}) | |
}); | |
} | |
function load_jquery(){ | |
var s=document.createElement('script'); | |
s.type='text/javascript'; |
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. |
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
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
{ | |
"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
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
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
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
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 |