Skip to content

Instantly share code, notes, and snippets.

View vstarck's full-sized avatar

Valentin Starck vstarck

  • Argentina
View GitHub Profile
@vstarck
vstarck / sleep_sort.js
Created June 16, 2011 12:55
Sleep Sort in JavaScript | http://t.co/nWJACyK
// from: http://dis.4chan.org/read/prog/1295544154/170
function sleepSort(list, callback) {
var result = [];
list.forEach(function(i) {
setTimeout(function() {
result.push(i);
if(result.length == list.length) {
callback(result);
@vstarck
vstarck / iterable.js
Created June 25, 2011 15:54
Implementacion de iteraciones basicas y metodos auxiliares
/**
* Constructor que provee de la funcionalidad
* de iteracion
*
* @constructor
*/
function Iterable() {}
/**
* Excepcion utilizada para detener la iteracion
@vstarck
vstarck / decorator.defer.js
Created August 22, 2011 19:55
Defer decorator
function deferDecorator(fn, scope) {
return function() {
var args = arguments;
setTimeout(function() {
fn.apply(scope, args);
}, 0);
}
}
@vstarck
vstarck / decorator.camelize.js
Created August 22, 2011 19:56
Camelize Decorator
// Decora la funcion camelizando su resultado
function camelizeDecorator(fn) {
return function() {
return fn.apply(null, arguments).replace(/[-\s_]+(.)?/g, function(match, chr) {
return chr ? chr.toUpperCase() : '';
});
}
}
function k(a) {
@vstarck
vstarck / decorator.bind.js
Created August 22, 2011 20:10
Bind Decorator
function bindDecorator(fn, scope) {
return function() {
fn.apply(scope, arguments);
}
}
var o = {
k:function() {
console.log(this);
},
@vstarck
vstarck / defer.execution.js
Created August 28, 2011 17:06
defer.execution.js
function say(hey) {
var what = [hey];
setTimeout(function() {
alert(what.join(' '));
}, 0);
return function w(hey) {
what.push(hey);
return w;
@vstarck
vstarck / string.stuff.js
Created August 29, 2011 15:20
String stuff
function sacarCharRepetidos(s) {
return s.split('').reduce(function(memo, chr) {
return memo += memo.indexOf(chr) == -1 ? chr : '';
}, '');
}
function letrasFaltantes(s) {
return s.split('').reduce(function(memo, chr) {
return memo.replace(chr, '');
}, 'abcdefghijklmnopqrstuvwxyz')
@vstarck
vstarck / vacio.legal.js
Created August 30, 2011 10:48
Vacio legal
@vstarck
vstarck / gejs5.3.js
Created August 30, 2011 11:03
gejs5.3.js
arr = [1,2,3,5,6,7,8,9,10]
arr.reduce(function(memo, current, index) {
return function() {
console.log(current);
memo();
}
}, function() {})();
// reduce executes the callback function once for each
@vstarck
vstarck / gejs5.3_2.js
Created August 30, 2011 17:59
gejs5.3_2.js
function loop(from, to, handler) {
(function cycle(n) {
[
eval,
function(n) {
handler(n);
cycle(n+1)
}
][1^(n/to)](n)
})(from);