Skip to content

Instantly share code, notes, and snippets.

View fabiomcosta's full-sized avatar
:octocat:
void 0

Fabio M. Costa fabiomcosta

:octocat:
void 0
View GitHub Profile
@fabiomcosta
fabiomcosta / sync-settimout-snippet.js
Created August 26, 2011 21:06
Mocks the setTimeout function with jasmine, making setTimeout dependent tests synchronous and easier to test.
// inside your beforeEach hook
spyOn(window, 'setTimeout').andCallFake(function(fn){
fn.apply(null, [].slice.call(arguments, 2));
return +new Date;
});
...
@fabiomcosta
fabiomcosta / niw.js
Created May 30, 2011 01:48
niw - A way to create new object from a constructor without the 'new' operator, just for fun and to emulate how the new operator works on pure javascript. WARNING - DO NOT USE IT ON YOUR PROJECTS
/*
code snippet by Fabio Miranda Costa
Its just for the purpose of understanding how the 'new' operator works.
Should work on gecko and webkit.
WARNING - DO NOT USE IT ON YOUR PROJECTS
*/
var niw = function(_constructor, args){
var newObj = {'__proto__': _constructor.prototype};
var ret = _constructor.apply(newObj, args);
/*
---
Port from the YUI3 event-simulate functionality to vanilla javascript.
...
*/
(function(global, document){
var mix = function(obj1, obj2){
for (var key in obj2){
obj1[key] = obj2[key];
var crypto = require("crypto");
var repeat = function(str, times){
var _str = str;
while(--times){
str += _str;
}
return str;
};
@fabiomcosta
fabiomcosta / msMatchesSelector_bug.js
Created February 20, 2011 20:02
msMatchesSelector errors on unattached nodes
// live demo: http://jsbin.com/oxuri5/9
var div = document.createElement('div');
div.setAttribute('attr', 'test');
console.log(div.msMatchesSelector('[attr="test"]'), ' should be true');
console.log(div.msMatchesSelector('[attr^="test"]'), ' should be true');
console.log(div.msMatchesSelector('[attr$="test"]'), ' should be true');
document.body.appendChild(div);
console.log(div.msMatchesSelector('[attr="test"]'), ' should be true');
console.log(div.msMatchesSelector('[attr^="test"]'), ' should be true');
(function(context){
var Configuration = context.Configuration = {};
Configuration.name = 'MooTools Slick';
Configuration.presets = {
'slick-1.0': {
sets: ['1.0'],
helpers: ['1.0'],
var getParent = function(expression){
var parsed = Slick.parse(expression);
parsed = parsed && parsed.expressions;
for (var i = parsed.length; i--;){
parsed[i][0] = '!';
}
return Slick.find(this, parsed);
};
/*
---
script: Elements.From.js
description: Returns a collection of elements from a string of html.
license: MIT-style license
requires: [Element]
if (!Browser.Element){
Element.parent = Object;
Element.ProtoType = {'$family': function(){ return 'element'; }.hide()};
Element.mirror(function(name, method){
Element.ProtoType[name] = method;
});
}
Type.isEnumerable = function(item){
return (typeof item != 'object' && typeof item != 'string' && typeof item.length == 'number');
};