Skip to content

Instantly share code, notes, and snippets.

View PatrickJS's full-sized avatar

PatrickJS PatrickJS

View GitHub Profile
@PatrickJS
PatrickJS / machine.js
Created March 16, 2022 07:01
Generated by XState Viz: https://xstate.js.org/viz
const routes = {
auth: {
login: "/auth/login",
reset: "/auth/reset-password"
},
apply: {
documents: "/apply/upload-docs",
income: "/apply/income",
name: "/apply/name",
review: "/apply/review",
@PatrickJS
PatrickJS / emit-all-plugin.js
Created February 28, 2022 23:20 — forked from DrewML/emit-all-plugin.js
Output every file in a webpack build to the specified dist directory in the webpack config. Each file is output after having each loader run against it, but before the webpack module wrapper is added.
const path = require('path');
module.exports = class EmitAllPlugin {
constructor(opts = {}) {
this.ignorePattern = opts.ignorePattern || /node_modules/;
}
shouldIgnore(path) {
return this.ignorePattern.test(path);
}
@PatrickJS
PatrickJS / getOrLoadRemote.js
Created February 27, 2022 09:38 — forked from ScriptedAlchemy/getOrLoadRemote.js
The Right Way to Load Dynamic Remotes
/**
*
* @param {string} remote - the remote global name
* @param {object | string} shareScope - the shareScope Object OR scope key
* @param {string} remoteFallbackUrl - fallback url for remote module
* @returns {Promise<object>} - Federated Module Container
*/
const getOrLoadRemote = (remote, shareScope, remoteFallbackUrl = undefined) =>
new Promise((resolve, reject) => {
// check if remote exists on window
@PatrickJS
PatrickJS / BrowserDeviceInfo.js
Created January 30, 2022 02:23
chrome emulated device info
var devices = [
{ name: 'Desktop - Huge', width: 2880, height: 1800, ratio: 2, type: 'desktop' },
{ name: 'Desktop - Extra Large', width: 1920, height: 1080, ratio: 1, type: 'desktop' },
{ name: 'Desktop - Large', width: 1440, height: 900, ratio: 1, type: 'desktop' },
{ name: 'Desktop - HiDPI', width: 1366, height: 768, ratio: 1, type: 'desktop' },
{ name: 'Desktop - MDPI', width: 1280, height: 800, ratio: 1, type: 'desktop' },
{ name: 'Laptop with HiDPI screen', width: 1440, height: 900, ratio: 2, type: 'desktop' },
{ name: 'Laptop with MDPI screen', width: 1280, height: 800, ratio: 1, type: 'desktop' },
{ name: 'Laptop with touch', width: 1280, height: 950, ratio: 1, type: 'desktop' },
{ name: 'Tablet - Portrait', width: 768, height: 1024, ratio: 1, type: 'tablet' },
@PatrickJS
PatrickJS / BrowserDeviceInfo.js
Created January 30, 2022 02:21 — forked from TrevorJTClarke/BrowserDeviceInfo.js
A quick list of browsers and devices for use in testing. Chrome is used for all devices that need simulation.
var devices = [
{ name: 'Desktop - Huge', width: 2880, height: 1800, ratio: 2, type: 'desktop' },
{ name: 'Desktop - Extra Large', width: 1920, height: 1080, ratio: 1, type: 'desktop' },
{ name: 'Desktop - Large', width: 1440, height: 900, ratio: 1, type: 'desktop' },
{ name: 'Desktop - HiDPI', width: 1366, height: 768, ratio: 1, type: 'desktop' },
{ name: 'Desktop - MDPI', width: 1280, height: 800, ratio: 1, type: 'desktop' },
{ name: 'Laptop with HiDPI screen', width: 1440, height: 900, ratio: 2, type: 'desktop' },
{ name: 'Laptop with MDPI screen', width: 1280, height: 800, ratio: 1, type: 'desktop' },
{ name: 'Laptop with touch', width: 1280, height: 950, ratio: 1, type: 'desktop' },
{ name: 'Tablet - Portrait', width: 768, height: 1024, ratio: 1, type: 'tablet' },
@PatrickJS
PatrickJS / haproxy.config
Created January 25, 2021 18:47 — forked from bwiggs/haproxy.config
HAProxy Config File Example
global
#debug # uncomment to enable debug mode for HAProxy
defaults
mode http # enable http mode which gives of layer 7 filtering
timeout connect 5000ms # max time to wait for a connection attempt to a server to succeed
timeout client 50000ms # max inactivity time on the client side
timeout server 50000ms # max inactivity time on the server side
backend legacy # define a group of backend servers to handle legacy requests
@PatrickJS
PatrickJS / GetOptimizationStatus.md
Created September 27, 2020 05:53 — forked from naugtur/GetOptimizationStatus.md
V8 %GetOptimizationStatus

%GetOptimizationStatus return a set of bitwise flags instead of a single value, to access the value, you need to take the binary representation of the returned value. Now, for example, if 65 is returned, the binary representation is the following:

(65).toString(2).padStart(12, '0');
// 000001000001

Each binary digit acts as a boolean with the following meaning:

@PatrickJS
PatrickJS / expired-map.ts
Last active August 31, 2020 18:09
this doesn't work in cloudflare workers where time doesn't change
export class ExpireMap extends Map {
expiring = new Map()
constructor(private _millis: number, private _getTime = this._getTime) {
super()
}
public set<T, V>(key: T, value: V): V {
const expire = this.getTime() + this._millis
this.expiring.set(key, expire)
super.set(key, value)
export class LRU extends Map {
constructor(private max: number) {
super();
}
/**
* Attemps to retrieve a value from the cache
* @param key The key of the entry to return from the cache
* @returns the value associated to the input key or undefined
*/