Skip to content

Instantly share code, notes, and snippets.

View quantizor's full-sized avatar
🦾

Evan Jacobs quantizor

🦾
View GitHub Profile
@quantizor
quantizor / script.sh
Created May 11, 2021 14:37
Vercel Ignored Build Step Diff Branch Against Master/Main
# Vercel only performs a depth=2 shallow repository clone, which makes performing branch-level diffs against your main branch
# impossible without manually fetching more data from git
#
# The following command checks if the origin remote is already set up and fetches it if not, then it performs a diff
# of the current branch being built against `main` (replace with `master` if your project is legacy)
#
# The bang (!) before `git diff` inverts the result because Vercel expects an exit code of 1 for triggering a new build
#
# Finally, if you want to filter the file list for only certain directory or file changes, you can add something like
# this after the `git diff ...` statement:
@quantizor
quantizor / use-promise-hook.js
Last active June 21, 2019 19:12
use-promise-hook
import { useEffect, useState } from 'react';
/**
* Pass a memoized promise getter (via useCallback) so we do not attempt to
* continuously re-request the promise.
*/
export default function usePromise(getPromise) {
const [loading, setLoading] = useState(true);
const [promise, setPromise] = useState();
const [error, setError] = useState();
@quantizor
quantizor / next.config.js
Created June 7, 2019 04:00
optimize nextjs webpack config
module.exports = {
webpack: config => {
if (config.mode === 'production' && config.name === 'client') {
config.optimization.splitChunks.cacheGroups.commons.minChunks = 2;
}
}
}
@quantizor
quantizor / sc.js
Last active August 17, 2018 21:08
test
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.styled={},e.React)}(this,function(e,t){"use strict";var r="default"in t?t.default:t,n=/([A-Z])/g;var a=function(e){return e.replace(n,"-$1").toLowerCase()},o=/^ms-/;var i=function(e){return a(e).replace(o,"-ms-")},s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},u=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),l=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r
@quantizor
quantizor / Home.js
Last active March 25, 2018 19:32
Buttermilk Holistic Example
export default () => "Home";
@quantizor
quantizor / svgEmbed.js
Last active February 22, 2018 17:03
SVG -> Data URI for CSS embedding
function prepareSVGAsDataURI(rawSVG) {
const prefix = 'data:image/svg+xml,';
let svg = encodeURIComponent(rawSVG.replace(/\n+/g, ''));
// restore ASCII-safe characters
svg = svg.replace(/%20/g, ' '); // spaces
svg = svg.replace(/%3D/g, '='); // equal signs
svg = svg.replace(/%3A/g, ':'); // colons
svg = svg.replace(/%2F/g, '/'); // slashes
@quantizor
quantizor / server.js
Created February 16, 2018 17:31
Isomorphic webpack HMR
/**
* initial setup:
*
* npm i babel-register chalk compression express lodash node-persist openport react-dev-utils@~0.5.2 webpack webpack-dev-middleware webpack-hot-middleware
*/
import 'babel-register';
import chalk from 'chalk';
import compression from 'compression';
@quantizor
quantizor / events.json
Last active February 14, 2018 04:19
example profiling plugin gist
This file has been truncated, but you can view the full file.
[{"ts":369004336107,"pid":49314,"tid":49314,"ph":"I","name":"TracingStartedInPage","id":1,"cat":"disabled-by-default-devtools.timeline","args":{"data":{"sessionId":"-1","page":"0xfff","frames":[{"frame":"0xfff","url":"webpack","name":""}]}}},
{"ts":369004336197,"pid":49314,"tid":49314,"ph":"I","name":"TracingStartedInBrowser","id":2,"cat":"disabled-by-default-devtools.timeline","args":{"data":{"sessionId":"-1"}}},
{"ts":369004405590,"pid":49314,"tid":49314,"ph":"b","name":"EntryOptionPlugin","id":3,"cat":"blink.user_timing"},
{"ts":369004405891,"pid":49314,"tid":49314,"ph":"e","name":"EntryOptionPlugin","id":3,"cat":"blink.user_timing"},
{"ts":369004606717,"pid":49314,"tid":49314,"ph":"b","name":"NodeSourcePlugin","id":4,"cat":"blink.user_timing"},
{"ts":369004606945,"pid":49314,"tid":49314,"ph":"e","name":"NodeSourcePlugin","id":4,"cat":"blink.user_timing"},
{"ts":369004606963,"pid":49314,"tid":49314,"ph":"b","name":"AMDPlugin","id":5,"cat":"blink.user_timing"},
{"ts":369004607020,"pid":49314,"tid":49314,"ph
@quantizor
quantizor / events.json
Created January 28, 2018 02:16
example profiling plugin gist
This file has been truncated, but you can view the full file.
[{"ts":210342517955,"pid":84888,"tid":84888,"ph":"I","name":"TracingStartedInPage","id":1,"cat":"disabled-by-default-devtools.timeline","args":{"data":{"sessionId":"-1","page":"0xfff","frames":[{"frame":"0xfff","url":"webpack","name":""}]}}},
{"ts":210342518021,"pid":84888,"tid":84888,"ph":"I","name":"TracingStartedInBrowser","id":2,"cat":"disabled-by-default-devtools.timeline","args":{"data":{"sessionId":"-1"}}},
{"ts":210342596877,"pid":84888,"tid":84888,"ph":"b","name":"EntryOptionPlugin","id":3,"cat":"blink.user_timing"},
{"ts":210342597223,"pid":84888,"tid":84888,"ph":"e","name":"EntryOptionPlugin","id":3,"cat":"blink.user_timing"},
{"ts":210342786095,"pid":84888,"tid":84888,"ph":"b","name":"NodeSourcePlugin","id":4,"cat":"blink.user_timing"},
{"ts":210342786350,"pid":84888,"tid":84888,"ph":"e","name":"NodeSourcePlugin","id":4,"cat":"blink.user_timing"},
{"ts":210342786357,"pid":84888,"tid":84888,"ph":"b","name":"AMDPlugin","id":5,"cat":"blink.user_timing"},
{"ts":210342786418,"pid":84888,"tid":84888,"ph

Notes

A loop isn't needed here at all. Just tail call parseDeclarationFlags as needed to replay the logic.

function parseDeclarationFlags(): StatementFlags {
    switch (token) {
        case SyntaxKind.VarKeyword: