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
export const encode = value => btoa(JSON.stringify(value)) | |
export const decode = value => JSON.parse(atob(value)) | |
export const save = (key, value) => localStorage.setItem(key, encode(value)) | |
export const load = key => decode(localStorage.getItem(key) ?? btoa('{}')) | |
export const estate = (state = {}, { | |
localStorageKey = 'state', | |
} = {}) => { | |
const isProxy = Symbol('isProxy') | |
const handler = { |
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
/* | |
CRITIQUE: It's missing fences | |
I need a distributed lock system for a service I'm writing. | |
(There can be multiple instances of this service running at | |
a time, and I need to make sure that only one instance does | |
a particular cron job.) | |
According to [this page](https://aws.amazon.com/s3/consistency/), |
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
export const merge = (target, ...sources) => { | |
target = { ...target } | |
if (!sources.length) return target | |
const source = sources.shift() | |
for(const key in source) { | |
const value = target[key] | |
const isObject = value | |
&& typeof value == 'object' | |
&& !(value instanceof Date) | |
&& !(value instanceof 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
const diff = (a, b, path = '') => { | |
let diffs = [] | |
const { | |
type: typeA, | |
value: valueA | |
} = diff.meta(a) | |
const { | |
type: typeB, | |
value: valueB | |
} = diff.meta(b) |
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 onOpen() { | |
var ui = SpreadsheetApp.getUi() | |
ui.createMenu('Utilities') | |
.addItem('Format Phone Numbers', 'formatPhone') | |
.addToUi(); | |
} | |
function formatPhone() { | |
const range = SpreadsheetApp.getActive().getActiveRange() | |
const values = range |
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
/** | |
* Simple command line argument parser | |
* | |
* An instance of Args is an array-like | |
* object that contains a list of fixed | |
* and named arguments | |
* | |
* Given command line args of: | |
* | |
* node args.js command -a --param=value |
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
{ | |
console.clear() | |
;(async function run() { | |
copyMembersWithoutCallings() | |
})() | |
async function copyMembersWithoutCallings() { | |
const urls = [ |
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
export class UnitWorkerManager { | |
private resolves = {} | |
private rejects = {} | |
private promiseId = 0 | |
private worker | |
constructor(scriptPath, opts) { | |
this.worker = new Worker(scriptPath, opts) | |
this.worker.addEventListener('message', data => { | |
const { id, err, result } = data || {} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>Test</title> | |
<style type="text/css"> | |
html{ | |
margin: 20px; | |
} | |
#stats{ | |
position: fixed; |
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
console.clear() | |
const Pid = (function(){ | |
// UUID generator | |
!function(n){"use strict";function e(){var e=n.crypto||n.msCrypto;if(!f&&e&&e.getRandomValues)try{var r=new Uint8Array(16);s=f=function(){return e.getRandomValues(r),r},f()}catch(n){}if(!f){var o=new Array(16);i=f=function(){for(var n,e=0;e<16;e++)0===(3&e)&&(n=4294967296*Math.random()),o[e]=n>>>((3&e)<<3)&255;return o},"undefined"!=typeof console&&console.warn&&console.warn("[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()")}}function r(){if("function"==typeof require)try{var n=require("crypto").randomBytes;c=f=n&&function(){return n(16)},f()}catch(n){}}function o(n,e,r){var o=e&&r||0,t=0;for(e=e||[],n.toLowerCase().replace(/[0-9a-f]{2}/g,function(n){t<16&&(e[o+t++]=y[n])});t<16;)e[o+t++]=0;return e}function t(n,e){var r=e||0,o=v;return o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+"-"+o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]+o[n[r++]]}functi |
NewerOlder