Skip to content

Instantly share code, notes, and snippets.

View ignacy's full-sized avatar
🦆
duck typing

Ignacy Moryc ignacy

🦆
duck typing
View GitHub Profile
# KOntroller:
class AuctionsController
# ....
def create
@auction = params[:auction][:type].constantize.new(params[:auction].merge(:calendar_validation => true, :private => false))
if @auction.save
redirect_to auction_products_path( @auction )
# Selenium, capybara - a way to click on a div
Then /^I click on "([^\"]*)" inside "([^\"]*)"$/ do |class_name, within|
locate(:css, "#{within} > #{class_name}").click
end
module B
def a
"a"
end
end
B.a #=> undefined method
module B
@ignacy
ignacy / gist:752871
Created December 23, 2010 11:48
loadandlive
$("#section_to_refresh").load(url+' #section_to_refresh>*','', function () {
$(".items_with_events").click(function() {
doStuff();
});
});
$(documment).unbind(".namespace");
$("#section_to_refresh").load(url+' #section_to_refresh>*','');
$(".items_with_events").click(function() {
// ....
});
class A
class << self
def foo
puts "foo"
end
end
end
A.foo
@ignacy
ignacy / gist:754825
Created December 25, 2010 11:06
Useless fibers example
fib = Fiber.new do
v = 0
loop do
v += 1
Fiber.yield v
v.times { print "-"}
puts v
end
end
require 'fiber'
def event_callback(letter)
puts "I've encountered #{letter} !!"
end
f = Fiber.new do
('a'..'z').each do |l|
Fiber.yield(event_callback(l)) if (l == "c" || l == "h")
end
test("booking gets proper starting coordinates at the begining", function() {
expect(2);
var event = jQuery.Event("mousedown.calendar");
event.pageX = 100;
event.pageY = 200;
jQuery(".weekday > .event_box").first().trigger(event);
equals(booking.startX, 100, "startX");
equals(booking.startY, 200, "startY");
});
@ignacy
ignacy / gist:754832
Created December 25, 2010 11:18
module pattern
var drawEvents = function() {
var popupExists = function (target) {
return !!jQuery(target).find("#sender").length;
};
var getLocationId = function(slots) {
if (!slots) {
return jQuery("#location_id").text();
} else {