Skip to content

Instantly share code, notes, and snippets.

View michaelwclark's full-sized avatar

Michael W Clark michaelwclark

View GitHub Profile
@michaelwclark
michaelwclark / randomPassword.js
Last active September 1, 2022 05:04
RandomPassword
const randomLetter = () => {
const alphabet = 'abcdefghijklmnopqrstuvwxyz';
return alphabet[Math.floor(Math.random() * alphabet.length)];
}
const randomNumber = () => {
return Math.floor(Math.random() * 10);
}
const randomSymbol = () => {
@michaelwclark
michaelwclark / EMA_8_21_CLOUD.pine
Created March 7, 2022 02:51
EMA CLOUDS 8/21 Pinescript
//@version=5
indicator(title='EMA 8/21 Clouds [GENOME]', shorttitle='EMA_8_21_G', overlay=true)
// EMA INPUTS
emaShortInput = input.int(8, minval=1, title='EMA Short Period')
emaLongInput = input.int(21, minval=1, title='EMA Long Period')
// GENERATE EMAS
emaShort = ta.ema(close, emaShortInput)
@michaelwclark
michaelwclark / keybase.md
Created September 19, 2019 16:05
keybase.md

Keybase proof

I hereby claim:

  • I am michaelwclark on github.
  • I am michaelwclark (https://keybase.io/michaelwclark) on keybase.
  • I have a public key ASDInzV3AK23fj-yZSl6b8f5wFesnhuZ3Nc_4jcfwPFagAo

To claim this, I am signing this object:

@michaelwclark
michaelwclark / example.js
Created March 27, 2019 14:01
Dependancy injection using Functional Composition
const DbProvider = params => {
console.log({params})
return {db :'db', ...params}
}
const LogProvider = params => {
console.log({params})
return {logger: 'logger', ...params}
}
@michaelwclark
michaelwclark / aspectRatio.js
Created February 12, 2019 22:57
gets the aspect ratio. Leaves a bit to be wanted.
const aspectRatio = (height, width, seperator=':')=> {
const gcd = (a, b) => b === 0 ? a : gcd(b, a % b)
const [h1, w1] = height < width ? [width, height] : [height, width]
const divisor = gcd(h1, w1)
return `${h1/divisor}${seperator}${w1/divisor}`
}
console.log(aspectRatio(549,500)) // 549:500
console.log(aspectRatio(1024,768)) // 4:3
@michaelwclark
michaelwclark / keepAliveProcessor.js
Created February 12, 2019 19:32
Allows for keepalive to be called every X ms while waiting for task to complete
//reqs:
// if task takes longer the X ms to complete then send a resposne to caller and continue to process task
const delay = (ms = 500) =>
new Promise(resolve => setTimeout(resolve, ms))
const taskA = async () => {
await delay(1200)
console.log('task A complete')
return 'A'
}
@michaelwclark
michaelwclark / HOC all in one.js
Created February 4, 2019 16:33
HOC POC vs Redux
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { loadAccountGraph } from 'redux/actions'
import { InlineLoader, ConditionalRender } from 'components'
import {
accountIdSelector,
accountLoadingSelector,
accountErrorSelector
} from 'redux/selectors'
import request from 'superagent-bluebird-promise'
@michaelwclark
michaelwclark / parseJsonDataToCSV.js
Last active October 18, 2018 18:34
Take in JSON files, flatten then and output as CSV.
import fs from 'fs'
function reduceJsonToCSV (jsonData, prefix = '') {
let parsedData = jsonData
try {
parsedData = JSON.parse(parsedData)
} catch (e) {}
const flatObj = Object.entries(parsedData).reduce((accum, [k, v]) => {
const cellPrefix = prefix ? `${prefix}.${k}` : k
@michaelwclark
michaelwclark / Round 2.js
Created August 31, 2018 16:37
functional fuckery to fucking fuck it up all the fucking time. Pardon my fucking french
const flat = arr => arr.reduce((a, c) => [...a, ...c])
const unique = arr =>
arr.reduce((a, c) => (a.includes(c) ? [...a] : [...a, c]), [])
const normalizeBy = (arr, key) =>
arr.reduce((a, c) => ({ [c[key]]: c, ...a }), {})
const normalizeByMongoId = arr => normalizeBy(arr, '_id')
Object.entries({ flat, unique, normalizeByMongoId, normalizeBy }).map(
arrayFunction =>
@michaelwclark
michaelwclark / createUniqueCombinationsFromArrays.js
Last active August 17, 2018 21:23
Combine N arrays into unique combinations
const createUniqueCombinationsFromArrays = (head, ...tail) =>
tail.length
? head.reduce((a, x) => [...a, ...createUniqueCombinationsFromArrays(...tail).map(_=>x+_)],[])
: head
const a1 = ['1','2','3','4']
const a2 = ['a','b']
const a3 = ['x','y']
const a4 = [':',',','?','!', '&']