This file contains hidden or 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 int32ToBytes (int) { | |
| return [ | |
| int & 0xff, | |
| (int >> 8) & 0xff, | |
| (int >> 16) & 0xff, | |
| (int >> 24) & 0xff | |
| ] | |
| } | |
| // 3 (base 10) = 00000000000000000000000000000011 (base 2) |
This file contains hidden or 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
| // Making custom error types | |
| // Taken from the comment at https://blog.getify.com/howto-custom-error-types-in-javascript/ | |
| // | |
| function makeErrorType() { | |
| var it = function (message) { | |
| if (!(this instanceof it)) { | |
| return new it(message); | |
| } | |
| this.message = message; | |
| this.stack = new Error(message).stack; |
This file contains hidden or 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
| 'use strict' | |
| function* fibo() { | |
| let [a,b] = [0,1]; | |
| while (true) { | |
| yield b; | |
| [a, b] = [b, a + b]; | |
| } | |
| } |
This file contains hidden or 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
| 'use strict' | |
| /** | |
| * flatten an array of arbitrarily nested arrays of integers into a flat array of integers | |
| */ | |
| function flat_numeric_arr(x, res) { | |
| res = res || []; | |
| if (typeof x === 'number') { | |
| res.push(x); | |
| } else if (Array.isArray(x)) { |
This file contains hidden or 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 today() { | |
| return new Date((new Date()).setHours(0, 0, 0, 0)); | |
| } |
This file contains hidden or 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 addMonths(date, months) { | |
| var d = new Date(date.getTime()); | |
| var m = d.getMonth(); | |
| var y = d.getFullYear(); | |
| var ym = y * 12 + m; | |
| ym = ym + months; | |
| m = ym % 12; | |
| y = (ym - m) / 12; | |
| d.setYear(y); | |
| d.setMonth(m); |
This file contains hidden or 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
| # kill all running node processes, except for Atom editor | |
| function kinod { | |
| read -r -p "Delete all node processes, except for Atom? [y/N] " response | |
| case $response in | |
| [yY][eE][sS]|[yY]) | |
| kill -9 `ps aux | grep node | grep -v grep | grep -v 'Atom.app' | awk '{print $2}'` | |
| ;; | |
| *) | |
| echo -- cancel -- | |
| ;; |
This file contains hidden or 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
| def permutations(n) | |
| _p n-1, (1..n).to_a, '' | |
| end | |
| def _p(n, arr, res) | |
| if n == -1 | |
| puts res | |
| return | |
| end | |
| (0..n).each do |m| |
This file contains hidden or 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
| #! /bin/bash | |
| # VirtualBoxGuestAddition install/upgrade for Mac OSX | |
| # | |
| # VirtualBox should be installed prior to running this script | |
| # | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "Please run as root" | |
| exit | |
| fi |
This file contains hidden or 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
| #! /bin/bash | |
| ## Based on and inspired by | |
| # https://medium.com/@icanhazedit/clean-up-unused-github-rpositories-c2549294ee45 | |
| ## Vars | |
| # 1. Your github user name | |
| USERNAME=john |
NewerOlder