Skip to content

Instantly share code, notes, and snippets.

View anonyco's full-sized avatar
🐕
I really like dogs. They are so fun to play with, simple to care for, and cute.

Jack anonyco

🐕
I really like dogs. They are so fun to play with, simple to care for, and cute.
  • United States
View GitHub Profile
@anonyco
anonyco / Undo And Redo Mutation Observer Records.js
Last active August 10, 2021 20:00
This sample code snippet demonstrates how to undo and redo a MutationRecord observed by a MutationObserver
//(function(){"use strict";
var Object_freeze = Object.freeze;
/**
* @param {!Array<MutationRecord>} mutationRecords
* @return {undefined}
*/
function redoMutations(undidMutations) {
if (undidMutations) for (var i=undidMutations.length|0, record, type, target, addedNodes, removedNodes, nextSibling, value; i; ) {
@anonyco
anonyco / staticCSSSnapshot.console.js
Created August 7, 2019 23:52
Quick & dirty way to inline all of the CSS on a page into style attributes from the console.
(function(){
const setProps = new WeakMap;
for (const ele of document.getElementsByTagName("*"))
setProps.set(ele, new Set);
function parseRules(ruleSet) {
for (const rule of ruleSet)
if (rule.type === 1) { // STYLE_RULE
for (const ele of document.querySelectorAll(rule.selectorText)) {
const setObj = setProps.get(ele);
@anonyco
anonyco / condensedValidJSVariableName.regex
Created August 19, 2018 18:01
Condensed javascript variable name validator regex (at the cost of speed)
^(?!(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$)(?:[$A-Z_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\
@anonyco
anonyco / CodeMirror.Destroy().js
Created July 30, 2018 02:26
A Destroy Method On All CodeMirror Objects To Ensure Garbage Collection
if (!CodeMirror.prototype.destroy) (function(){
// A destroy extension. Absolutely positively beyond a shadow of a doubt obliterate a CodeMirror instance from memory.
function hasExclusion(stringArr, regexpArr){
return function(exclusion){
var iSA = stringArr.length, cur = null, iEL = 0, iC = 0, iRA = regexpArr.length;
if (isRegExp(exclusion)){
while (iRA--)
if (regexpArr[iRA].source === exclusion.source && regexpArr[iRA].flags === exclusion.flags)
return iRA;
} else {
@anonyco
anonyco / varName.js
Last active April 22, 2020 13:21
Efficient Javascript Valid Variable Name Helper Functions
// This file aims to provide a quick, fast, small-as-possible-while-avoiding-encoding-errors solution for those who
// are interested in parsing javascirpt files using javascript. What this does do is it determines whether a string
// is a valid javascript variable name according to the variable name's code points. What this script does not do is
// determine whether or not that variable is already a reserved keyword. If you need that check, then look elsewhere.
// NOTE: This is the unminified file-part. To use this file, place this file INSIDE the global IIFE around your code
// before any calls to it. But, don't distribute it just yet. The source code is rather large. Instead, you must
// minify it before you incorperate it into the end product website using the closure compiler. Online access to the
// Closure Compiler can be found at https://closure-compiler.appspot.com.