Skip to content

Instantly share code, notes, and snippets.

@konijn
konijn / index.html
Last active October 30, 2019 11:41 — forked from RomanPerekhrest/index.html
test_cycle #jsbench #jsperf (http://jsbench.github.io/#11a2b8507a7f9290c6ef6cda596f8179) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>test_cycle #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@konijn
konijn / powerSet.js
Last active January 4, 2016 00:39
powerSet
function powerSet( list ){
var set = [],
listSize = list.length,
combinationsCount = (1 << listSize);
for (var i = 1; i < combinationsCount ; i++ , set.push(combination) )
for (var j=0, combination = [];j<listSize;j++)
if ((i & (1 << j)))
combination.push(list[j]);
return set;
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="ISEE Math Challenge Generator" />
<meta charset=utf-8 />
<title></title>
</head>
<body>
</body>
function sortfunction(a, b)
{
return (a - b) //causes an array to be sorted numerically and ascending
}
function canWeDoIt( target , a )
{
if( a.length == 1 )
return (a[0] == target);
if( a[0] == target )
@konijn
konijn / permute.js
Created November 18, 2013 16:10
Permute
/* Permute will give all permutations for the provided array ( sourceSet )
do not provide usedSet nor permutationSet
Based on http://stackoverflow.com/a/9960925/7602
*/
function permute( sourceSet , usedSet , permutationsSet ) {
permutationsSet = permutationsSet || [];
usedSet = usedSet || [];
for (var i = 0; i < sourceSet.length; i++) {
usedSet.push( sourceSet.splice(i, 1)[0] );
if (!sourceSet.length)
@konijn
konijn / gist:7529404
Created November 18, 2013 15:13
Nicely format number in js
function formatNumber( n , precision )
{
n = n * 1;
return n.toLocaleString().split(".")[0] + "." + n.toFixed( precision || 2 ).split(".")[1];
}
@konijn
konijn / gist:6636750
Created September 20, 2013 12:30 — forked from shamansir/gist:3007244
Overlapping squares in js
// Excerpt from: https://github.com/Animatron/player/blob/master/anm.collisions.js
function edgeTest(p1, p2, p3, r2) {
var rot = [ -(p2[1] - p1[1]),
p2[0] - p1[0] ];
var ref = (rot[0] * (p3[0] - p1[0]) +
rot[1] * (p3[1] - p1[1])) >= 0;
for (var i = 0, il = r2.length; i < il; i+=2) {
@konijn
konijn / prime.js
Last active December 14, 2015 14:18
function isPrime( n )
{
if( n < 2 )
return false
if( n < 4 )
return true;
if( n % 2 == 0 )
return false;
if( n % 3 == 0 )
return false;
@konijn
konijn / gist:4635185
Last active December 11, 2015 17:29
Log in the console all globals, still will not tell you where you created the global..
/* Dump all 'user space' globals
Many thanks to glutamat: http://stackoverflow.com/questions/14585537 */
void( (function()
{
var w = document.body.appendChild( document.createElement("iframe") ).contentWindow,
known =
[
"screenLeft" , "screenTop" , "scrollX" , "scrollY" , "pageYOffset" , "pageXOffset" , /* Scrolling related built-ins */
"innerWidth" , "innerHeight" , "outerWidth" , "outerHeight" , /* Size related built-ins */
"defaultstatus" , "defaultStatus", /* Status bar text related built-ins */
@konijn
konijn / compose.js
Created August 19, 2014 18:52
Compose
function merge(object, boltOn) {
//Simply merge the properties of boltOn into object
for(var property in boltOn)
if(boltOn.hasOwnProperty(property))
object[property] = boltOn[property];
return object;
}
function compose( /*Constructor1, Constructor2, ..*/ ) {
//Keep a closure reference for later