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