Skip to content

Instantly share code, notes, and snippets.

View mrosata's full-sized avatar
🐣

Michael Rosata mrosata

🐣
  • Quincy, MA USA
View GitHub Profile
@mrosata
mrosata / fp-either-monad.js
Last active April 22, 2024 07:16
Functional JavaScript Monad Classes - (Maybe Just Nothing) - (Either Left Right) (IOMonad) and my type checking utils
import is from './is-util';
/**
* Either Monad class (from Functional Programming in JavaScript)
*/
class Either {
constructor(value) {
this._value = value;
}
get value () {
@mrosata
mrosata / flower-power.py
Last active October 7, 2023 11:08
Python Turtle Flower... Stack like recursion
#!/usr/bin/python
# Udacity exercise. Just posted the code here to help anyone who wanted to see the work behind my posted result.
__author__ = 'Michael Rosata mrosata1984@gmail.com'
__package__ = ''
from random import random
import turtle
class TurtleArtist(turtle.Turtle):
_origin = (0, 0)
@mrosata
mrosata / la-ramda.js
Last active January 15, 2023 01:47
A subset of the Ramda library written using arrow functions, "lamda-ramda". The purpose of this is fun and to use in environments where importing 3rd party libs isn't allowed. Feel free to add to this.
const R = new LaRamda()
/**
* A subset of custom implementations of functions from
* the Ramda library. (all in Lamda form)
* - thanks to @xgrommx for uniq, intersection, where, evolve,
* applySpec, defaultTo, both, either, cond, zipWith
*/
function LaRamda () {
const I = x => x
@mrosata
mrosata / jsbin-functional-program.js
Created November 16, 2016 04:50
Functional Programming with IO, Maybe, Just, Nothing -- Touch of Reactive
console.clear()
// The Ramda Library functions you need to breathe.
const Maybe = iJustMetYouThisIsCrazyImAMonadSoCallMeMaybe()
const {
map, chain, compose, reduce, filter, prop, curry
} = R
// fromEvent :: Str -> Elem -> Obs
const fromEvent = curry((eventType, elem) => {
return Rx.Observable.fromEvent(elem, eventType)
@mrosata
mrosata / map-functional-args.js
Created April 23, 2017 00:45
A better order for the arguments to the map function
// One suggestion I have on the way I wrote map in this video:
// https://www.youtube.com/watch?v=qTeeVd8hOFY
// Instead of passing the transform function as the last param
// and the array as the first... it would be better to pass the
// transformFn first and the array as the last parameter to map.
function map (transformFn, array) {
const rv = []
for (let i = 0; i < array.length; i++) {
@mrosata
mrosata / memioze-with-ttl.js
Created February 12, 2019 18:37
Cache functions that return promises with a TTL
/**
* Memioze a function with a TTL
* @param func {function} The function to memioze (can return promise)
* @param ttl {number?} milliseconds to cache results (default = 30000)
* @param ttlError {number?} milliseconds to cache errors (default = ttl = 30000)
* @param initialValue {*} an optional value to return before initial func() result
* @return {{get: (function(...[*]=): Promise<*>), clear: (function(): void)}}
*/
export function memoizeWithTTL ({ func, ttl = 30000, ttlError = ttl, initialValue }) {
Verifying my Blockstack ID is secured with the address 15TypPzhtG7tupJbtybU8p7oxjrYHsGkwf https://explorer.blockstack.org/address/15TypPzhtG7tupJbtybU8p7oxjrYHsGkwf
@mrosata
mrosata / denode-aws-service-code.js
Last active January 8, 2018 17:11
Generates code to wrap entire AWS service apis as functions or methods returning Promises. Setup: `yarn add ramda yargs`
#!/usr/bin/node
////////////////////////////////////////////////////////////////////////////////
//// Create AWS Service Promisified Functions
//// @author Michael Rosata
////
//// @dependencies ramda, yargs
////
//// @desc
//// Returns the code that would wrap every method from one AWS Service into
//// functions that return Promises rather than those returning Node style
@mrosata
mrosata / .env.local
Created December 19, 2017 16:53
The React Starter Kit public/index.html template with Facebook Account Kit
REACT_APP_FB_APP_ID="12345-abcde"
REACT_APP_FB_ACCOUNT_KIT_VERSION="v1.2"
REACT_APP_META_THEME_COLOR="#FAFEFA"
REACT_APP_HTML_TITLE="React/Redux/Reselect Starter"
"""
Merge together .csv files. I'm creating this because I have 30 .csv files which need to be concatenated
together. This uses the headers from 1 file and then will concate w/o headers 1 through n such as :
"customer-data.csv", "customer-data (1).csv" ... "customer-data (n).csv"
"""
# Todo: make use of the csv module and check headers from each file to make sure data lines up.
# Todo: allow explicit filenames to be passed in as well as lists of files
import csv
class CSV_Monster: