Skip to content

Instantly share code, notes, and snippets.

View dmi3y's full-sized avatar
🌵
Dill with it

Dmitry Lapshukov dmi3y

🌵
Dill with it
  • Planet Earth
View GitHub Profile

#Automated Unit testing with YUI3

  • YUI Test Library, plays good with all YUI infostructure.
  • Yeti, tool for automation cross browser tests.
  • Full automation build process support, tools like PhantomJS

##Terminology

TDD - Test Driven Development
BDD - Behaivior Driven Development

function make_promise() {
var status = 'unresolved',
outcome,
waiting = [],
dreading = [];
function vouch (deed, func) {
switch (status) {
case 'unresolved':
(deed === 'fulfilled' ? waiting: dreading).push(func);
@dmi3y
dmi3y / async-pubsub.js
Last active December 20, 2015 23:39
Async publisher subscriber for YUI3, intern solution cause weird behavior of custom events when fire them globally. Sandbox/playground http://jsbin.com/ibubaq/10/edit, SO http://stackoverflow.com/questions/18158657/yui3-custom-async-events-not-working-on-y-global
YUI.add('async-pubsub', function(Y) {
'use strict';
if (!YUI.asyncPubSub) {
YUI.namespace('asyncPubSub');
YUI.asyncPubSub = (function() {
var eventsFired = {}, eventsSubscribed = {};
function doPublishFor(eventName) {
var subscribers = eventsSubscribed[eventName],
@dmi3y
dmi3y / findNthPrime.js
Last active December 20, 2015 08:29
Prime numbers toolset
function findNthPrime(n) {
'use strict';
var
range = primeRange(n),
min = range.min,
max = range.max,
median,
primes = [2,3,5,7,11];
while ( primes.length < n ) {
function once (func) {
return function () {
func.apply(this, arguments);
func = null;
};
}
function hi(name) {
console.log("Hi %s", name);
@dmi3y
dmi3y / gist:5378707
Last active December 16, 2015 04:39
call function in defined interval http://jsbin.com/oxuziy/5/edit
(function(){
var i = 0, n = 5, f;
(function f() {
setTimeout (
function() {
console.log(i++);
i <= n? f(): '';
},
1000
);
@dmi3y
dmi3y / handler loop
Created April 4, 2013 13:04
handle onclick in older fashon
// http://jsbin.com/ubugag/2/edit
var allDivs = document.getElementsByTagName("div"),
length = allDivs.length, divDomID,
showCarHandler = function(){
var divDomINT = parseInt(this.id.replace("car_", 0), 10);
console.log(divDomINT);
};
for(;length--;){
@dmi3y
dmi3y / addClass.js
Last active December 14, 2015 20:49
at some point addClass function
function addClass(myElement, classToAdd) {
if (!myElement && !classToAdd) return;
var
myElementIsSting = typeof myElement == 'string',
myElementNode = myElementIsSting? document.getElementById(myElement): myElement,
classes = ' ' + (myElementNode.className || '') + ' ',
classToAdd = ' ' + classToAdd + ' ';
if (!~classes.indexOf(classToAdd)) { // http://stackoverflow.com/questions/12299665/what-does-a-tilde-do-when-it-precedes-an-expression
function calcFromStr(str) {
var ops = ['*','/','+','-'];
var reg = /(\b\D)/;
var calc = str.split(reg);
function calculator(l, op, r) {
switch( op ) {
case '*':
return l*r;
@dmi3y
dmi3y / findintersections.js
Last active August 29, 2015 14:25
Find intersections
// http://jsbin.com/mapena/edit?js,console
// http://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript
function findIntersctions(a, b) {
var ai = 0;
var bi = 0;
var out = [];
while( ai < a.length && bi < b.length ) {
if( a[ai] > b[bi] ) {