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
| var array = [1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0, 1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0, 1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0, 1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0, 1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0, 1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0, 1, 7, 5, 9, 0, 4, 12, -56, 7, 0, -45, 8, 2, 3, 6, 7, 8, 1, 5, 0]; | |
| var getRandomInt = function (min, max) { | |
| return Math.floor(Math.random() * (max - min)) + min; | |
| }; | |
| var quick_sort = function (unsorted) { | |
| if (unsorted.length === 0 || unsorted.length === 1) { | |
| return unsorted; | |
| } |
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
| export NVM_DIR="/Users/darkruby/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm | |
| if [ -f "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" ]; then | |
| GIT_PROMPT_THEME=Default | |
| source "$(brew --prefix bash-git-prompt)/share/gitprompt.sh" | |
| fi | |
| if [ -f $(brew --prefix)/etc/bash_completion ]; then | |
| . $(brew --prefix)/etc/bash_completion |
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
| const compose = (...funcs) => { | |
| const noop = (arg) => arg; | |
| return funcs.reduceRight((acc, func) => { | |
| return (arg) => func(acc(arg)); | |
| }, noop); | |
| }; |
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
| const dropwhile = (predicate, list) => { | |
| return list.reduce((acc, item) => { | |
| if (acc.drop) { | |
| const drop = predicate(item); | |
| const list = drop ? acc.list : [...acc.list, item]; | |
| return { drop, list }; | |
| } | |
| return {drop: false, list: [...acc.list, item]} | |
| }, {drop: true, list: []}).list; | |
| }; |
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
| const fs = require('fs'); | |
| const dataFileBuffer = fs.readFileSync('./train-images-idx3-ubyte'); | |
| const labelFileBuffer = fs.readFileSync('./train-labels-idx1-ubyte'); | |
| const pixelValues = []; | |
| for (let image = 0; image <= 59999; image++) { | |
| const pixels = []; | |
| for (let x = 0; x <= 27; x++) { | |
| for (let y = 0; y <= 27; y++) { |
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
| # https://downloads.pwnedpasswords.com/passwords/pwned-passwords-1.0.txt.7z | |
| # https://downloads.pwnedpasswords.com/passwords/pwned-passwords-update-1.txt.7z | |
| import hashlib | |
| def _hash(password): | |
| p = password.encode('utf-8') | |
| m = hashlib.sha1() | |
| m.update(p) | |
| return m.hexdigest().upper() |
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
| type Item<T> = { val: T, rest: List<T> } | null; | |
| type List<T> = Item<T>; | |
| const cons = <T>(val: T, rest: List<T>) => ({ val, rest }); | |
| const empty = () => null; | |
| const fold_left = <T, A>(func: (acc: A, val: T) => A, list: List<T>, acc: A): A => { | |
| //poor man's pattern matching | |
| switch (list) { | |
| case empty(): return acc; | |
| default: { |
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
| type rod = list(int); | |
| exception InvalidMove(int, int); | |
| exception OtherMove(rod, rod); | |
| let moveRods = (a: rod, b: rod) : (rod, rod) => | |
| switch (a, b) { | |
| | ([x, ...xs], []) => (xs, [x]) | |
| | ([x, ...xs], [y, ...ys]) when x < y => (xs, [x, y, ...ys]) |
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
| let next = (seq: list(int)) : int => | |
| switch (seq) { | |
| | [] => 0 | |
| | [0] => 1 | |
| | [x, y, ..._] => x + y | |
| }; | |
| let fib = (n: int) : list(int) => { | |
| let rec fib' = (m: int, seq: list(int)) : list(int) => | |
| switch (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
| class StateMonad<S, A> { | |
| constructor(public runState: (s: S) => ({ s: S, a: A })) { | |
| } | |
| static return_<S, A>(a: A): StateMonad<S, A> { | |
| return new StateMonad(s => ({ s, a })); | |
| } | |
| bind<B>(func: (a: A) => StateMonad<S, B>): StateMonad<S, B> { | |
| return new StateMonad<S, B>((s: S) => { |