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 / memioze-with-ttl.js
Created February 12, 2019 18:37
Cache functions that return promises with a TTL
View memioze-with-ttl.js
* 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 }) {
View gist:07b72ba0b7d08ab011eda483c7caadb4
Verifying my Blockstack ID is secured with the address 15TypPzhtG7tupJbtybU8p7oxjrYHsGkwf
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`
View denode-aws-service-code.js
//// 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 / .env.local
Created December 19, 2017 16:53
The React Starter Kit public/index.html template with Facebook Account Kit
View .env.local
REACT_APP_HTML_TITLE="React/Redux/Reselect Starter"
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.
View la-ramda.js
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
View higher-order-lamda.js
// If we wrote a multiply function:
const multiply = (n, m) => n * m
// If we wrote an expression:
[ 1, 2, 3, 4, 5 ].map( (m) => multiply(10, m) )
// It would evaluate to:
[ 10, 20, 30, 40, 50 ]
// But we could also write that example like:
const multBy = (n) => (m) => n * m
// And then if we wrote an expression:
mrosata / map-functional-args.js
Created April 23, 2017 00:45
A better order for the arguments to the map function
View map-functional-args.js
// One suggestion I have on the way I wrote map in this video:
// 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 / snippet-video-download-link.js
Last active April 1, 2017 18:35
Browser Snippet to quickly get a download link for a video displayed on current page. Only tested on a couple sites. Targets 'src' attribute on <video> element or <source> element.
View snippet-video-download-link.js
View explaination.js
/* Explaination for the code around 25mins of
// We have 4 helper functions
const mult = (a, b) => a * b;
const sum = (a, b) => a + b;
// this is how the curried "apply" behaves.
const apply = (fn) => (...args) => fn.apply(null, args);
// we don't need to mess up the gist with zip.
const zip = `fahghetttaahhh booowwwwttt it`;
View controllers.application.js
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Email Message Demo'