Skip to content

Instantly share code, notes, and snippets.

View noomorph's full-sized avatar

Yaroslav Serhieiev noomorph

  • Wix.com
  • Ukraine
  • 01:58 (UTC +03:00)
View GitHub Profile
@noomorph
noomorph / advanced-multidispatch.rb
Last active December 24, 2015 11:29
What I want to do with my 'multidispatch' gem
lass Foo
include Multidispatch
def bar
"bar"
end
def bar(a, n=1)
"#{a} bar #{n}"
end
@noomorph
noomorph / knowledge.rb
Last active December 28, 2015 04:59
Metakoans 1-7 passed, 8-9 yet
module ::Kernel
@@default_values = {}
def initialize
@@default_values.each_pair do |attr_name, value|
variable = :"@#{attr_name}"
instance_variable_set variable, value
end
end
@noomorph
noomorph / my_struct.rb
Last active December 28, 2015 04:59
RubyGarage home task. Creates the class with the same capabilities as Struct
class MyStruct
def self.new(*attributes, &block)
Class.new do
attributes.each do |attr|
attr_accessor attr
end
define_method :initialize do |*values|
values.each_with_index do |value, index|
attribute = attributes[index]
@noomorph
noomorph / netjs_RegistrationPageObject.js
Created June 21, 2014 04:52
RegistrationPageObject — accessing elements
function RegistrationPageObject(container) {
this.container = container;
this.elements = {
age: this.container.querySelector("input[id=age]"),
agree: this.container.querySelector("input[id=agree]"),
female: this.container.querySelector("input[id=female]"),
gender: this.container.querySelectorAll("input[name=gender]"),
male: this.container.querySelector("input[id=male]"),
name: this.container.querySelector("input[id=name]"),
@noomorph
noomorph / netjs_onchange.js
Created June 21, 2014 04:57
onchange issue
// Looks like this does not work:
// this.container.querySelector("input[id=name]").value = "John A.";
function simulateChange(element) {
var evt;
if ("createEvent" in document) {
evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
element.dispatchEvent(evt);
describe("form field: age", function () {
before(function () {
this.input = this.page.elements.age;
this.field = this.input.parentElement;
this.label = this.field.querySelector("label");
});
it("should have label marked valid", function () {
this.label.className.should.not.match(/invalid/);
});
var script = document.createElement("SCRIPT");
script.src = "/path/to/mocha.js";
script.onload = function () { /* … */ };
script.onerror = function () { /* … */ };
var head = document.getElementsByTagName("head")[0];
head.appendChild(script);
describe("survey app", function () {
describe_registration_form(function () {
when_fields_are_empty(function () {
after_submit(function () {
validation_suite_for_registration({
name: false,
age: false,
gender: false,
agree: false
});
function waitForCondition(condition, timeout, rejectReason) {
timeout = timeout || 5000; // 5 secs by default
rejectReason = "waited for " + timeout + "ms " +
"until " + (rejectReason || "something to happen");
return new Promise(function (resolve, reject) {
var result = condition(),
timerId,
pollId;
function naiveWait(condition, callback) {
var pollId = setInterval(function () {
if (condition()) {
clearInterval(pollId);
resolve(result);
}
}, 10);
}