Skip to content

Instantly share code, notes, and snippets.

View Josh-Miller's full-sized avatar

Josh Miller Josh-Miller

  • Finn Ridge Capital
View GitHub Profile
@perry-mitchell
perry-mitchell / encryption-example.js
Last active February 27, 2022 09:55
Encryption and decryption using AES CBC in NodeJS, with key derivation
const { pbkdf2: deriveKey } = require("pbkdf2");
const crypto = require("crypto");
const DERIVATION_ROUNDS = 200000;
const HMAC_KEY_SIZE = 32;
const PASSWORD_KEY_SIZE = 32;
function pbkdf2(password, salt, rounds, bits) {
return new Promise((resolve, reject) => {
deriveKey(password, salt, rounds, bits / 8, "sha256", (err, key) => {
@ThomasHambach
ThomasHambach / express-joi-typescript-validate-middleware.ts
Last active September 25, 2019 19:05
Express + Joi + Typescript validation middleware
app.get("/some-endpoint", validate({...}), (req, res, next) => {});
module Main where
import Prelude
import Data.Exists (Exists, mkExists, runExists)
import Unsafe.Coerce (unsafeCoerce)
-- Leibniz equality:
-- Two things are equal if they are substitutable in all contexts.
type Leib a b = forall f. f a -> f b
@superseb
superseb / cleanup.sh
Last active November 26, 2025 14:21
Cleanup host added as custom to Rancher 2.0
#!/bin/sh
# OUTDATED: please refer to the link below for the latest version:
# https://github.com/rancherlabs/support-tools/blob/master/extended-rancher-2-cleanup/extended-cleanup-rancher2.sh
docker rm -f $(docker ps -qa)
docker volume rm $(docker volume ls -q)
cleanupdirs="/var/lib/etcd /etc/kubernetes /etc/cni /opt/cni /var/lib/cni /var/run/calico /opt/rke"
for dir in $cleanupdirs; do
echo "Removing $dir"
rm -rf $dir
done
@DrBoolean
DrBoolean / three_envs.js
Last active May 24, 2021 02:31
Tail of three envs
const compose = (f, g) => x => f(g(x))
const Id = x =>
({
fold: f => f(x),
map: f => Id(f(x))
})
Id.of = Id
const Tuple = (_1, _2) =>
@andrevdm
andrevdm / Scotty_websockets.hs
Last active March 6, 2024 01:51
Using websockets with scotty haskell
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Protolude
import qualified Web.Scotty as Sc
import qualified Data.Text as Txt
import qualified Network.Wai.Middleware.Gzip as Sc
@abiodun0
abiodun0 / reselectRamda.js
Last active November 10, 2017 17:19
Reselect Done with Ramda function
const createSelector = (...fns) => R.memoize(R.converge(R.last(fns), R.init(fns)))
// test case
const selector = createSelector(
state => state.a,
state => state.b,
(a, b) => console.log('Called!') || ({
c: a * 2,
d: b * 3
@busypeoples
busypeoples / UIPattern.re
Last active January 28, 2019 15:31
Slaying a UI Anti Pattern in ReasonML
/*
Slaying a UI Anti Pattern in ReasonML
Based on Kris Jenkins original writing.
http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html
*/
type remoteData 'e 'a =
| NotAsked
| Loading
| Failure 'e
| Success 'a;
@abiodun0
abiodun0 / contramap-functor.js
Last active August 13, 2021 21:11
Contramap and functors in js. react as an example
import React from 'react'
// Comp:: a -> JSX;
const Comp = g => ({
fold: g,
contramap: f => Comp(x => g(f(x))),
concat: other => Comp((x) => <div> {g(x)} {other.fold(x)} </div>)
});
// Reducer :: (a, b) -> a
@001101
001101 / accounting.sql
Created February 18, 2017 09:08 — forked from NYKevin/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...