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 / 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"
@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
// 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
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 / 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.
/* Explaination for the code around 25mins of
* https://www.youtube.com/watch?v=4ECoOX5QZEg&lc=z13jjdxj3waze5aam04cdre5llyaspvi25c.1486236089300698
*/
// 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`;
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Email Message Demo'
});