Skip to content

Instantly share code, notes, and snippets.

@ironboy
ironboy / wordlist.txt
Created September 5, 2015 21:40
English wordlist
aardvark
aardwolf
aaron
aback
abacus
abaft
abalone
abandon
abandoned
abandonment
@ironboy
ironboy / bit.js
Created September 4, 2015 22:50
Bit test in js
function bit_test(num,bit){
return ((num>>bit) % 2 != 0)
}
function bit_set(num,bit){
return num | 1<<bit;
}
function bit_clear(num,bit){
return num & ~(1<<bit);
@ironboy
ironboy / Array shuffle.js
Created September 4, 2015 20:37
Shuffle an array - return a shuffled copy (keep original intact)
Array.prototype.shuffle = function(){
var x = this.slice(), y = [];
while(x.length){y.push(x.splice(Math.floor(Math.random()*x.length),1)[0]);}
return y;
}
@ironboy
ironboy / towers.js
Created August 30, 2015 22:42
Towers of Hanoi - non-recursive
/*
Towers of Hanoi
(non-recursive solution)
https://blog.svpino.com/2015/06/07/programming-challenge-towers-of-hanoi
*/
function solveHanoi(discs){
var towers = {a:[],b:[],c:[]};
/*
Solution to
https://blog.svpino.com/2015/05/24/programming-challenge-the-position-of-the-element
*/
function posOfEl(list,el){
// if the element exist return the index
var index = list.indexOf(el);
if(index>=0){return index;}
// otherwise insert it in a copy
/*
Solution to:
https://blog.svpino.com/2015/05/17/programming-challenge-merging-overlapping-intervals
*/
function combineOverlappingIntervals(intervals){
var overlapping = [], newOnes = [];
// Compare each interval with every other interval
@ironboy
ironboy / collides.jquery.js
Created August 30, 2015 20:28
check if two dom elements collide
/*
jQuery.collides plugin: collides
- simple collisionDetection
© 2014 Thomas Frank, v 0.7b
Check if one or more objects (DOM elments) collides
with one or more other objects (DOM elements)
If object collides the callbackFunc will be triggered.
@ironboy
ironboy / deepCopy.js
Last active August 30, 2015 20:22
A deep copier for JavaScript
/*
A deep copier for JavaScript
that can handle circular references,
copies objects with correct prototypes,
copies functions (rather than referencing them),
copies non-enumerable properties
and copies HTML- and jQuery-elements as references
*/
function deepCopy(obj){
@ironboy
ironboy / solutions.js
Last active May 5, 2024 07:31
Solutions to some programming problems.
/*
Five Programming Problems
a software developer should be able
to solve in less than an hour
https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour
Thomas Frank, Solutions in JS, time taken:
45 minutes (almost all time spent on problem 4 and 5)
@ironboy
ironboy / protomini.js
Created August 26, 2015 09:27
Minimal prototypical inheritance patterns
// A minimal polyfill for Object.assign
// (an ES6 feature)
Object.assign = Object.assign || function(){
for(var i = 1; i < arguments.length; i++){
for(var j in arguments[i]){
arguments[0][j] = arguments[i][j];
}
}
};