Skip to content

Instantly share code, notes, and snippets.

View venil7's full-sized avatar
turning coffee into code

Art Deineka venil7

turning coffee into code
View GitHub Profile
@venil7
venil7 / quick-sort.js
Last active August 29, 2015 14:20
quick sort
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;
}
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
const compose = (...funcs) => {
const noop = (arg) => arg;
return funcs.reduceRight((acc, func) => {
return (arg) => func(acc(arg));
}, noop);
};
@venil7
venil7 / dropWhile.js
Last active November 23, 2016 12:07
recursive, functional dropWhile & sort
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;
};
@venil7
venil7 / idx_ubyte_to_json.js
Last active January 31, 2021 01:42
MNIST: IDX ubyte to JSON, for JavaScript Machine Learning
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++) {
# 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()
@venil7
venil7 / list.ts
Last active September 19, 2019 18:07
TypeScript Linked List (Haskell/OCaml)
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: {
@venil7
venil7 / hanoi-tower.re
Created March 10, 2018 17:45
quick implementation of the Tower Of Hanoi problem
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])
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) {
@venil7
venil7 / state-monad.ts
Last active January 31, 2020 13:06
State Monad in TypeScript
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) => {