This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Determines if an object is freed | |
@param obj is the object of interest | |
@param freeFn is a function that frees the object. | |
@returns a promise that resolves to {freed: boolean, memoryDiff:number} | |
@author Steve Hanov <steve.hanov@gmail.com> | |
*/ | |
function isObjectFreed(obj, freeFn) { | |
return new Promise(resolve => { | |
if (!performance.memory) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* :: (Function | string, number | bigint, ...any) -> Function */ | |
const setBigTimeout = (fn, delay, ...args) => { | |
const maxSafeDelay = typeof delay === 'bigint' | |
? BigInt(2147483647) | |
: 2147483647 | |
let id | |
const cancel = () => { | |
clearTimeout(id) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import * as _ from 'lodash' | |
/*---------------------------------------------------------------------------*\ | |
USER | |
\*---------------------------------------------------------------------------*/ | |
const UserContext = React.createContext() | |
const UserProvider = withRouter(class UserProvider extends React.Component { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const capitalise = word => | |
word[0].toUpperCase() + word.slice(1).toLowerCase() | |
/** (val: any) -> string */ | |
const typeOf = val => { | |
if (val === null) return 'null' | |
if (val === void val) return 'undefined' | |
if (Number.isNaN(val)) return 'NaN' | |
if (Array.isArray(val)) return 'Array' | |
if (RegExp.prototype.isPrototypeOf(val)) return 'RegExp' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** (fn: Function) -> Function **/ | |
const curry = (fn) => { | |
/** (fn: Function, totalArgs: number) -> Function **/ | |
const curryFunc = (fn, totalArgs) => { | |
const curriedFunc = (...args) => { | |
if (args.length === 0) { | |
throw new Error('Please provide the required arguments') | |
} | |
if (totalArgs === args.length) return fn(...args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -------------------------------------------------------------------------- *\ | |
* Solution | |
\* -------------------------------------------------------------------------- */ | |
/** :: (val: any) -> boolean */ | |
const isNull = val => val === null | |
/** :: (list: Function, start: number) -> Function */ | |
const slice = (list, start = 0) => idx => list(idx + start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -------------------------------------------------------------------------- *\ | |
* Utils | |
\* -------------------------------------------------------------------------- */ | |
const isFunction = val => typeof val === 'function' | |
/** | |
* Trampoline | |
*/ | |
const T = fn => (...args) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* PATH: -> ./src/redux/modules/widgets.js | |
* | |
* [RULES] | |
* | |
* A module... | |
* | |
* - MUST export default a function called reducer() | |
* - MUST export its action creators as functions | |
* - MUST have action types in the form npm-module-or-app/reducer/ACTION_TYPE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore } from './lib' | |
/** | |
* Main reducer | |
*/ | |
const counter = function (state = 0, action) { | |
switch (action.type) { | |
case 'INCREMENT': | |
return state + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Undefined cannot be assigned using window.undefined = someVal or | |
* undefined = someVal but can be changed using function scope. | |
* window.undefined is the same as window['undefined'] | |
* | |
* The same example does not work with the null keyword and program throws | |
* a syntax error (function (null) {...})(123) | |
*/ | |
;(function (undefined) { | |
// x is undefined |
NewerOlder