Skip to content

Instantly share code, notes, and snippets.

View clshortfuse's full-sized avatar
😀
Reinventing the internet...

Carlos Lopez clshortfuse

😀
Reinventing the internet...
  • 14:32 (UTC -05:00)
View GitHub Profile
@clshortfuse
clshortfuse / builder.js
Created March 6, 2023 21:05
JS XML Parser and Builder
/**
* @template T
* @typedef {import('./index.js').TupleTree<T>} TupleTree<T>
*/
/**
* @template T
* @typedef {import('./index.js').TupleTreeEntry<T>} TupleTreeEntry<T>
*/
@clshortfuse
clshortfuse / JSONEventSource.js
Created January 14, 2023 06:15
EventSource extension with JSON parsing and FireFox workaround
/**
* @implements {EventSource}
*/
export default class JSONEventSource {
#closeCalled;
#url;
#initArgs;
@clshortfuse
clshortfuse / worker.js
Created November 8, 2022 18:03
runAsync for Web
import AsyncObject from './AsyncObject.js';
/** @type {AsyncObject<Worker>} */
const workerConstructor = new AsyncObject();
/** @return {Promise<Worker>} */
async function getConstructor() {
if (workerConstructor.hasValue()) {
return workerConstructor.value;
}
@clshortfuse
clshortfuse / base64.js
Created July 11, 2022 00:35
es6 base64 encoder and decoder
const BIT_MASK_6 = 0b11_1111;
const BIT_MASK_8 = 0b1111_1111;
const CODEPOINT_SINGLE_LIMIT = 0x00_80;
const CODEPOINT_DOUBLE_LIMIT = 0x08_00;
const CODEPOINT_TRIPLE_LIMIT = 0x1_00_00;
const CODEPOINT_QUAD_LIMIT = 0x11_00_00;
const CODEPOINT_EXTRA_BYTE = 0b10 << 6;
const BASE64_CHAR_62 = '+';
@clshortfuse
clshortfuse / network.js
Created March 2, 2021 17:22
fetch() operations
export class NetworkError extends Error {
/**
* @param {string} message
* @param {number} status
*/
constructor(message, status) {
super();
this.status = status;
}
}
@clshortfuse
clshortfuse / customevent.js
Created October 26, 2020 17:22
EventTarget & CustomEvent Shims
/**
* @template T
* @typedef {Object} CustomEventShimPrivateFields<T>
* @prop {T} detail
* @prop {string} type
* @prop {any} target
* @prop {any} currentTarget
* @prop {number} eventPhase
* @prop {boolean} bubbles
* @prop {boolean} cancelable
@clshortfuse
clshortfuse / script.js
Created August 1, 2020 13:11
Dynamically load script as a Promise
/**
* @param {string} url
* @param {boolean} [useCredentials=false]
* @param {string} [integrity]
* @return {Promise<void>}
*/
export function loadScript(url, useCredentials, integrity) {
return new Promise((resolve, reject) => {
const scripts = document.head.getElementsByTagName('script');
for (let i = 0; i < scripts.length; i += 1) {
/**
*
* :: cookies.js ::
*
* A complete cookies reader/writer framework with full unicode support.
*
* Revision #3 - July 13th, 2017
*
* https://developer.mozilla.org/en-US/docs/Web/API/document.cookie
* https://developer.mozilla.org/User:fusionchess
@clshortfuse
clshortfuse / expressJWT-sample.js
Last active November 12, 2019 17:30
Express-Controlled JWT
import express from 'express';
import cors from 'cors';
import { sign, verify } from 'jsonwebtoken';
/**
* @typedef AuthToken
* @prop {string=} sub UserID
* @prop {number} iat Issuance date in seconds
* @prop {number=} exp Expiration date in seconds
*/
@clshortfuse
clshortfuse / awsdeployer.js
Created September 11, 2019 15:29
AWS S3/CloudFront Deployer Webpack Plugin
// const path = require('path');
// const AWS = require('aws-sdk');
// const mime = require('mime');
// const crypto = require('crypto');
/**
* @typedef {Object} AWSDeployer.CloudFrontInvalidation
* @prop {string} id
* @prop {string[]} paths
*/