Skip to content

Instantly share code, notes, and snippets.

View Coutlaw's full-sized avatar

Cass Outlaw Coutlaw

View GitHub Profile
@Coutlaw
Coutlaw / scalafmtTest
Created June 28, 2018 18:00
run scala fmt tests and check style
sbt clean scalafmt test:scalafmt scalastyle test
@Coutlaw
Coutlaw / filterinputJS.js
Created June 29, 2018 14:57
filter inputs in javascript
const mkLender = (assignedLender, category) => {
if (assignedLender) {
const input = assignedLender.toLowerCase().replace(/ /g, '');
if (input.startsWith("userid:")) {
const x = /userid:(\d+)/i.exec(input);
if (x != null)
return {
assignedUser: {"userId": parseInt(x[1])},
category: mkCategory(category)
};
@Coutlaw
Coutlaw / preGitPush.txt
Created July 2, 2018 15:14
pre git push
# for node
npm run-script lint
# if errors
npm run-script lintfix
# to test
npm test
# for scala
sbt clean scalafmt test:scalafmt scalastyle test
https://monix.io/ | Monix
https://www.youtube.com/watch?v=Zt6LjUnOcFQ | (12) The Type Astronaut's Guide to Shapeless—Dave Gurnell - YouTube
https://jto.github.io/articles/getting-started-with-shapeless/ | Getting started with Shapeless
https://github.com/clvv/fasd | clvv/fasd: Command-line productivity booster, offers quick access to files and directories, inspired by autojump, z and v.
https://www.scala-lang.org/blog/2017/11/30/bloop-release.html | Meet bloop, a fast tool to compile and test your project | The Scala Programming Language
https://docs.google.com/spreadsheets/d/1PkYmXkEl_r1QeP66URj_I8psp-OTuVlb2utFi0LMqd4/edit#gid=0 | ZapierDemo - Google Sheets
@Coutlaw
Coutlaw / snow.sh
Created October 19, 2018 13:10
make it snow in terminal
ruby -e 'C=`stty size`.scan(/\d+/)[1].to_i;S=["2743".to_i(16)].pack("U*");a={};puts "\033[2J";loop{a[rand(C)]=0;a.each{|x,o|;a[x]+=1;print "\033[#{o};#{x}H \033[#{a[x]};#{x}H#{S} \033[0;0H"};$stdout.flush;sleep 0.1}'
@Coutlaw
Coutlaw / retrieval_script.md
Last active April 9, 2020 18:49
Mongo Cluster Migration Assistant in Go

Mongodb Node IP Retrieval Tool in Go

I was using the migrate-mongo npm package to create indexes on a 3 node mongo cluster running in AWS. The package required IP addresses to be placed in the config.js file for the migration to locate the remote cluster. To accomplish this I created a go script to retrieve the IP addresses and update the config file for migrations. The script will use the .aws credential file on the machine its running on.

About The Migration Library

Migration Package Structure

The migration package has the following structure

@Coutlaw
Coutlaw / key_generator_script.md
Last active April 9, 2020 18:49
S3 Credential File Key Generator in Go

Key Generation With S3 Credential Files in Go

This script can be used to generate unique keys from credential files in an AWS S3 bucket. If we needed a key that was a hash of the ClientID and Client Secret, then we can use the below script to find a key for every file in a given S3 bucket. This script will use the .aws credential file on the machine that it is running on.

My Script

package main

import (
	"crypto/sha256"
@Coutlaw
Coutlaw / retryWithDelay.js
Last active January 29, 2020 01:38
Recursive retry with exponential backoff in node JS
// A delay function used for our queries
const delay = ms => new Promise(res => setTimeout(res, ms));
// Recursively try the base query when the results are null
// Delay time is 2 seconds and doubles each retry
const baseRetry = ({lead_id}, numberOfRetry = 5, delayMs = 2000) => {
return delay(delayMs).then(() => queryFunction({queryParam}).then((resp = {}) => {
const { potentiallyNullValueFromQuery } = resp;
if(numberOfRetry > 0 && !potentiallNullValueFromQuery ) {
// Retry the query recursively, removing a number of retries remaining
return queryFunction({queryParam}, numberOfRetry - 1, delayMs * 2);
@Coutlaw
Coutlaw / redux.js
Created April 8, 2020 13:48
Redux cycle
console.clear();
// Creating action creators for 3 actions: creating a policy, creating a claim, deleting a policy
// action creator: people dropping off a form
const createPolicy = (name, amount) => {
return { // action, a form in our analogy
type: 'CREATE_POLICY',
payload: {
name: name,
@Coutlaw
Coutlaw / clippy_solution.rs
Created May 19, 2020 10:39
Rustlings: clippy 1 & 2
// Clippy 1 problem (this does not compile because float comparison)
fn main() {
let x = 1.2331f64;
let y = 1.2332f64;
if y != x {
println!("Success!");
}
}
// Clippy1 solution