This file contains hidden or 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 fnParamsRe = /^(?:async)?\s*(?:(?:function\s+[a-zA-Z_][a-zA-Z0-9_]*|function|[a-zA-Z_][a-zA-Z0-9_]*)\s*(?:\(([^)]*)\))|(?:\(([^)]*)\)|([a-zA-Z_][a-zA-Z0-9_]*))\s*=>\s*{)/ | |
const sepRe = /\s*,\s*/g | |
const getFnParams = fn => { | |
const source = fn.toString() | |
const match = fnParamsRe.exec(source) || [] | |
const paramStr = match[1] || match[2] || match[3] || '' | |
return paramStr.split(sepRe).filter(Boolean) | |
} |
This file contains hidden or 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 throttlePromiseFn = module.exports = (fn, { max = 8, PromiseConstructor = Promise } = {}) => { | |
const queue = []; | |
let count = 0; | |
const call = (params, resolve, reject) => { | |
const promise = fn(...params); | |
promise.then((value)=>{ | |
checkQueue(); | |
typeof resolve === 'function' && resolve(value); | |
}).catch((reason)=>{ | |
checkQueue(); |
This file contains hidden or 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 bigInt = require("big-integer") | |
const symbols = `0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`; | |
const v2r = (n, b) => { | |
if(!bigInt.isInstance(n)) n = bigInt(n); | |
let digits = ''; | |
while(n > 0){ | |
let r = n.divmod(b); | |
digits = symbols[r.remainder] + digits; | |
n = r.quotient; |
This file contains hidden or 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 EventBusFactory = () => { | |
let repo = {}; | |
return { | |
add(key, fn){ | |
if(typeof fn !== 'function') throw `Invalid parameter. Second parameter must be a function.`; | |
if(!repo[key]) repo[key] = []; | |
if(!repo[key].includes(fn)) repo[key].push(fn); | |
}, | |
remove(key, fn){ | |
if(!repo[key]) return; |
This file contains hidden or 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
var showCopy = (text) => { | |
let div = document.createElement('DIV'); | |
let btn = document.createElement('BUTTON'); | |
btn.textContent = 'Copy'; | |
btn.style.border = 'solid 1px #aaa'; | |
btn.style.background = '#fefefe'; | |
btn.style.padding = '1em 3em'; | |
btn.style.fontSize = '16px'; | |
btn.addEventListener('click', (e)=>{ | |
let textarea = document.createElement('TEXTAREA'); |
This file contains hidden or 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
{ | |
console.clear(); | |
let app = (()=>{ | |
function Invocable(name, fn){ | |
this.name = name; | |
this.fn = fn; | |
} | |
let bagOfThings = {}; | |
let getFnParams = (fn) => { |
This file contains hidden or 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
// COMMON CODE | |
const DEFAULT_SENDER = '[email protected]'; | |
const Email = require('some-email-service'); | |
// EXAMPLE 1 | |
let emailOne = (person, subject, body) => { | |
let email = new Email(); |
This file contains hidden or 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
// Draft 2 | |
ngm.service('searchArray', function(){ | |
let THRESHHOLD = 0; | |
let FULL_EXACTMATCH_MODIFIER = 1.0; | |
let FULL_STARTSWITH_MODIFIER = 0.9; | |
let FULL_CONTAINS_MODIFIER = 0.3; | |
let FULL_PARTIAL_MODIFIER = 0.3; | |
let PRECISION = 2; | |
let re = /[\s\b]+/g; | |
let search = (term, arr, key) => { |
This file contains hidden or 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
// #region MISC | |
/* | |
Usage: | |
<image-input content-id="{{show.id}}" image-type="Show" ng-model="show.images"></image-input> | |
<image-input content-id="{{show.id}}" image-type="ListImage" ng-model="show.listImage"></image-input> | |
*/ |
This file contains hidden or 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
// This code is for infinite scrolling, which we may or may not implement | |
var wrapper = $('.test-scroll-wrapper'); | |
var content = $('.test-scroll-content'); | |
window.wrapper = wrapper; | |
window.content = content; | |
wrapper.on('scroll', function(){ | |
var marginTop = Math.round(parseFloat(content.css('marginTop'))); |