This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(Date.prototype, 'isWeekday', { | |
value: function(UTC) { | |
var day = (UTC ? this.getUTCDay : this.getDay)(); | |
if (day === 0 || day === 6) | |
return false; | |
else | |
return true; | |
}, | |
writable: true, configurable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.deepFreeze = function deepFreeze(obj) { | |
this.freeze(obj) | |
for (var key in obj) { | |
var prop = obj[key] | |
if (obj.hasOwnProperty(key) && prop instanceof this && !this.isFrozen(prop)) | |
this.deepFreeze(prop) | |
} | |
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The MIT License (MIT) | |
Copyright (c) 2014 Rohit Vighne | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hasWebGL () { | |
try { | |
return !!(WebGLRenderingContext && document.createElement('canvas').getContext('webgl')) | |
} catch (e) { | |
if (!(e instanceof TypeError || e instanceof ReferenceError)) | |
throw e | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The MIT License (MIT) | |
Copyright (c) 2014 Rohit Vighne | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The MIT License (MIT) | |
Copyright (c) 2014 Rohit Vighne | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sumDigits(n) { | |
var sum = 0; | |
while (n !== 0) { | |
sum += n % 10; | |
n = Math.floor(n / 10); | |
} | |
return sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function probablyPrime(n, k) { | |
// Always prime | |
if (n === 2 || n === 3) | |
return true; | |
// Never prime | |
if (n % 2 === 0 || n < 2) | |
return false; | |
// Write (n - 1) as 2^s * d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <cmath> | |
#include <vector> | |
struct Triangle { | |
int a, b, c; | |
}; | |
inline int gcd(int a, int b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
SYNTAX: | |
Generator treeIterator(Node root, int whatToShow, bool function filter(Node)) | |
- root: The parent node. It is not returned. | |
- whatToShow: Bitmask of the NodeFilter.SHOW_* static constants. Represents the types of nodes included. | |
- filter: Predicate returning whether the node given as the first argument should be included in the iteration. | |
Instead of a boolean, it may return a NodeFilter.FILTER_* static constant. | |
A return value of `true` is implicitly converted to `NodeFilter.FILTER_ACCEPT`, | |
and `false` becomes `NodeFilter.FILTER_REJECT` | |