Skip to content

Instantly share code, notes, and snippets.

@patrickroberts
patrickroberts / auto-mdn.user.js
Last active March 18, 2019 19:06
Auto-complete MDN documentation links
// ==UserScript==
// @name Auto-MDN
// @namespace http://tampermonkey.net/
// @version 3.3
// @description Auto-complete MDN documentation links
// @author Patrick Roberts
// @match https://stackoverflow.com/*
// @grant GM_xmlhttpRequest
// @require https://cdn.jsdelivr.net/gh/mitchellmebane/GM_fetch@e9f8aa00af862665625500e2c2459840084226b4/GM_fetch.min.js
// @require https://cdn.jsdelivr.net/npm/diffhtml/dist/diffhtml.min.js
// ==UserScript==
// @name Stack Overflow Sticky Search Filter
// @namespace http://tampermonkey.net/
// @version 0.0.0
// @description Use localStorage to remember most recently used search filter
// @author Patrick Roberts
// @match https://*.stackoverflow.com/*
// @grant none
// ==/UserScript==
@patrickroberts
patrickroberts / lookup.js
Last active May 26, 2018 17:43
A Map whose values are Sets
class Lookup extends Map {
get [Symbol.toStringTag] () { return 'Lookup' }
constructor (iterable = []) {
super(
[...iterable].map(
([key, value]) => [
key,
value instanceof Set
? value
@patrickroberts
patrickroberts / deobfuscate.js
Last active May 21, 2018 01:34
UMD for asynchronously generating a deobfuscation effect with customizable attributes
((root, factory) => {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory)
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS.
module.exports = factory()
} else {
// Browser globals (root is window)
root.deobfuscate = factory()
@patrickroberts
patrickroberts / compiler.js
Last active May 9, 2022 15:58
Math expression compiler using PEG.js parser generator to build expression tree
/*
* parser.pegjs -> parser.js
* https://pegjs.org/online
* Use results cache, Optimize parsing speed
*/
// import parser generator for grammar defined in parser.pegjs
const { parse } = require('./parser')
// accepts mapping to convert parameter list into named parameters based on position
const args = (expression, map) => (...args) => expression(map(...args))
@patrickroberts
patrickroberts / cache.js
Last active January 24, 2018 14:02
Hashlife in Node.js using WeakMap and Set
class Cache extends WeakMap {
get (key) {
// initialize to empty set
if (!super.has(key)) {
super.set(key, new Set())
}
return super.get(key)
}
}
@patrickroberts
patrickroberts / alu32.v
Created December 23, 2017 18:54
Recursive ALU module in Verilog HDL
`timescale 1ns / 1ps
module alu32 (d, Cout, V, a, b, Cin, S);
output[31:0] d;
output Cout, V;
input [31:0] a, b;
input Cin;
input [2:0] S;
wire [31:0] c, g, p;
// ==UserScript==
// @name Automated Permalink
// @namespace http://tampermonkey.net/
// @version 2.0
// @description automatically synchronizes permalink to fusion
// @author Patrick Roberts
// @match http://pokemon.alexonsager.net/*
// @grant none
// ==/UserScript==
@patrickroberts
patrickroberts / base64.js
Last active September 18, 2017 22:34
standard test fail (possible bug)
function characterRange (minCharacter, maxCharacter) {
const lower = minCharacter.charCodeAt(0)
const upper = maxCharacter.charCodeAt(0)
return Array(upper - lower + 1)
.fill()
.map((_, index) => String.fromCharCode(lower + index))
.join('')
}
@patrickroberts
patrickroberts / wav.babel.js
Last active November 1, 2016 05:00
WAV music synthesizer class
'use strict';
(function () {
WAV.frequency = function frequency(note) {
var map = {
'REST': 0,
'A0': 27.5,
'A0#': 29.135,
'B0b': 29.135,
'B0': 30.868,