Skip to content

Instantly share code, notes, and snippets.

View ScriptedAlchemy's full-sized avatar
🎯
Focusing

Zack Jackson ScriptedAlchemy

🎯
Focusing
View GitHub Profile
@ScriptedAlchemy
ScriptedAlchemy / Worker.js
Created May 6, 2018 09:04
IPFS gateway worker interceptor
'use strict'
const IPFS = require('ipfs')
function App() {
let node
create()
@ScriptedAlchemy
ScriptedAlchemy / md5.js
Last active July 21, 2022 06:43
Super fast MD5 Hashing function, useful for arbitrary hashing needs.
/* eslint-disable */
function md5cycle(x, k) {
let a = x[0];
let b = x[1];
let c = x[2];
let d = x[3];
a = ff(a, b, c, d, k[0], 7, -680876936);
d = ff(d, a, b, c, k[1], 12, -389564586);
import $$observable from 'symbol-observable'
import ActionTypes from './utils/actionTypes'
import isPlainObject from './utils/isPlainObject'
import combineReducers from './combineReducers'
/**
* Creates a Redux store that holds the state tree.
* The only way to change the data in the store is to call `dispatch()` on it.
*
@ScriptedAlchemy
ScriptedAlchemy / setTimeout-mem-leak.js
Created August 10, 2019 23:05 — forked from irazasyed/setTimeout-mem-leak.js
JavaScript: setTimeout Memory Leak Prevention.
// https://developer.mozilla.org/en-US/docs/Web/API/window.setTimeout
var timeoutID;
delayedAlert();
function delayedAlert() {
timeoutID = window.setTimeout(slowAlert, 2000);
}
function slowAlert() {
@ScriptedAlchemy
ScriptedAlchemy / index.js
Created September 2, 2019 19:43
Render Manifest Webpack Plugin
compilation.mainTemplate.hooks.renderManifest.tap(
'URLImportPlugin',
(result, { chunk }) => {
console.log(chunk);
const renderedModules = Array.from(chunk.modulesIterable).filter(
(module) => module.type === MODULE_TYPE
);
if (renderedModules.length > 0) {
result.push({
@ScriptedAlchemy
ScriptedAlchemy / deepmerge.js
Created September 2, 2019 20:39
Immutable Deep merge
function mergeDeep(...objects) {
const isObject = obj => obj && typeof obj === 'object';
return objects.reduce((prev, obj) => {
Object.keys(obj).forEach(key => {
const pVal = prev[key];
const oVal = obj[key];
if (Array.isArray(pVal) && Array.isArray(oVal)) {
prev[key] = pVal.concat(...oVal);
@ScriptedAlchemy
ScriptedAlchemy / Chunksplitting.js
Last active November 25, 2019 00:49
Split Chunks cache groups via module api
function hasExternalizedModule(module) {
const moduleSource = module?.originalSource?.()?.source?.() || '';
// dead simple way to check if the magic export comment is in a file
if (moduleSource?.indexOf('externalize') > -1 || false) {
return moduleSource;
}
return false;
}
const interleaveConfig = test => ({
@ScriptedAlchemy
ScriptedAlchemy / App1.js
Last active November 25, 2019 00:49
Interleaved magic export
// Menu.js
import React from 'react';
const Nav = ({items}) => {
return (<nav><ul>{items.map(Item=><Item/>)}</ul></nav>)
}
export const alert = (message) => {
alert(message)
@ScriptedAlchemy
ScriptedAlchemy / Index.js
Last active November 25, 2019 00:49
[contenthash] for webpack module ids
const createHash = require('webpack/lib/util/createHash');
const usedIds = new Set();
compilation.hooks.beforeModuleIds.tap('URLImportPlugin', (modules) => {
for (const module of modules) {
// if the module has an id, and its got a path to a real file
if (module.id === null && module.resource) {
const hash = createHash(this.opts.hashFunction || 'md4');
// grab the resource path, without any loader queries
@ScriptedAlchemy
ScriptedAlchemy / EntryManifest.js
Last active November 25, 2019 00:49
Interleaved Manifest
if(!window.entryManifest) {window.entryManifest = {}};
window.entryManifest["some-namespace"] = {
"commons.js": {
"path": "static/chunks/commons.7343b2658e7f703389c2.js",
"isInitial": true
},
"static/runtime/webpack.js.js": {
"path": "static/runtime/webpack-035ac2b14bde147cb4a8.js",
"isInitial": true