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
c_cyan=`tput setaf 6` | |
c_red=`tput setaf 1` | |
c_green=`tput setaf 2` | |
c_sgr0=`tput sgr0` | |
parse_git_status() { | |
local color="" | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then |
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 wrapLineAtDivisibleColumn(line) { | |
var column = 80; | |
while (line.length / column % 1) --column; | |
return line.replace(new RegExp('.{' + column + '}(?!$)', 'g'), '$&\n'); | |
} |
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
// high-resolution time diff in milliseconds | |
function hrmstime(t) { | |
if (t) { | |
t = process.hrtime(t); | |
return (t[0] * 1e9 + t[1]) / 1e6; | |
} | |
return process.hrtime(); | |
} | |
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
// Takes a number and clamps it to within the provided bounds. | |
#define Clamp(_num, _min, _max) MIN((_max), MAX((_min), (_num))) | |
// Check if the two floats are equal. | |
#define FloatEqual(A, B) (ABS((A) - (B)) < FLT_EPSILON) | |
// Check if the two floats are NOT equal. | |
#define FloatNotEqual(A, B) (ABS((A) - (B)) > FLT_EPSILON) | |
// Check if the float is equal to zero. |
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
// Fisher-Yates shuffle | |
function shuffle(array) { | |
for (var n = array.length, k, x; 1 < n;) { | |
k = Math.floor(Math.random() * n--); | |
x = array[n]; | |
array[n] = array[k]; | |
array[k] = x; | |
} | |
} |
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
/** | |
* Converts degrees to radians. | |
* @param {number} angleDegrees Angle in degrees. | |
* @return {number} Angle in radians. | |
**/ | |
function degreesToRadians(angleDegrees) { | |
return angleDegrees * Math.PI / 180; | |
} | |
/** |
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
// Converts degrees to radians. | |
#define degreesToRadians(angleDegrees) (angleDegrees * M_PI / 180.0) | |
// Converts radians to degrees. | |
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / M_PI) |
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 insertAt(arr, val, i) { | |
arr.splice(i, 0, val); | |
} | |
function removeAt(arr, i) { | |
return arr.splice(i, 1).length === 1; | |
} | |
function genericInsertAt(arr, val, i) { | |
Array.prototype.splice.call(arr, i, 0, val); | |
} |
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 fibonacci(n) { | |
return n < 2 ? n : fibonacci(n - 2) + fibonacci(n - 1); | |
} | |
function fibonacci(n) { | |
var prev, curr = 0, next = 1; | |
while (n-- > 0) { | |
prev = curr; | |
curr = next; | |
next = prev + curr; |
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
@interface NSIndexSet (Operations) | |
// http://en.wikipedia.org/wiki/Union_(set_theory) | |
- (NSIndexSet *)unionWith:(NSIndexSet *)other; | |
// http://en.wikipedia.org/wiki/Intersection_(set_theory) | |
- (NSIndexSet *)intersectionWith:(NSIndexSet *)other; | |
// http://en.wikipedia.org/wiki/Complement_(set_theory)#Relative_complement | |
- (NSIndexSet *)relativeComplementIn:(NSIndexSet *)universe; |
OlderNewer