Skip to content

Instantly share code, notes, and snippets.

View oyvindkinsey's full-sized avatar

Øyvind Sean Kinsey oyvindkinsey

View GitHub Profile
@oyvindkinsey
oyvindkinsey / array_permutate.js
Created January 3, 2014 00:07
array permutations
function array_permutate(set /*, additionalSets*/ ) {
var additionalSets = Array.prototype.slice.call(arguments, 1);
if (additionalSets.length === 0) {
return set.map(function (item) { return [item]; });
}
var permutations = array_permutate.apply(null, additionalSets);
var result = [];
for (var i = 0; i < set.length; i++) {
for (var j = 0; j < permutations.length; j++) {
result.push([set[i]].concat(permutations[j]));
@oyvindkinsey
oyvindkinsey / 1.js
Created February 23, 2013 03:59 — forked from padolsey/1.js
/x/==x
var input = 'ABbCcc\n\
Good luck in the Facebook Hacker Cup this year!\n\
Ignore punctuation, please :\n)\
Sometimes test cases are hard to make up\n.\
So I just go consult Professor Dalves';
input.split('\n').forEach(function(line) {
console.log(
line,
@oyvindkinsey
oyvindkinsey / README.md
Created November 20, 2012 22:27
Core implementation needed for ES5 to ES3 transforms using 'jspatch'

Core implementation needed for ES5 to ES3 transforms using 'jspatch'

  1. Install jsgrep
  2. Convert your source code using node spatch-cli.js es5-to-es3.spatch source.js // yields the converted source
  3. Prepare the implementation of ES5 by implemeting the missing polyfills in es5.js
  4. Concat es5.js and the converted code
  5. Wrap the result of the previous steps in a closure and export your object
var mylib = (function() {
var api = {
provide: function(name, fn) {
this[name] = fn;
}
};
...
api.provide('foo', function() {
...
});
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src =
('//' + /(www|apps)\.([\w\.]+\.)facebook\.com/.exec(document.referrer)
? RegExp.$2 + '.facebook.com/assets.php/en_US/'
: 'connect.facebook.net/en_US/') +
// the module to load
// Based on Angus Croll's http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
// Also available at http://jsfiddle.net/7xAqT/
Object.toType = (function() {
var global = this,
toString = Object.prototype.toString;
return function(obj) {
if (obj === global) {
return "Global";
}
// this is the code available in the page
var DEBUG_LOG = (function () {
var timer = null, timeout = 5000;
var head;
return {
add: function (item) {
head = { value: item, next: head };
if (timer) {
clearTimeout(timer);
//
// by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
// MIT Style License
// see also: http://wiki.ecmascript.org/doku.php?id=strawman:iterators
//
// ---------------------------------------
// 1. Iteration via for-in loop
// ---------------------------------------
@oyvindkinsey
oyvindkinsey / Weird switch statement.js
Created January 19, 2011 16:22
How to make 'if x <= foo, else if x <= faa' statments elegant..
var a = 23;
switch (true){
case a <= 25:
//do foo
break;
case a <= 30:
// do faa
break;
default: