Skip to content

Instantly share code, notes, and snippets.

View nojvek's full-sized avatar

Noj Vek nojvek

View GitHub Profile
const fs = require('fs');
const fetch = require('node-fetch');
const GH_TOKEN = process.env.GH_TOKEN;
const repo = 'recurrency/frontend';
if (!GH_TOKEN) {
console.error(`need env var GH_TOKEN`);
console.log(process.env);
process.exit(1);
}
@nojvek
nojvek / introspection.gql
Created June 17, 2021 01:50
GraphQL Introspection query
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
subscriptionType { name }
types {
...FullType
}
directives {
name
/**
* returns a function that returns true when node matches the matcher.
* matchers can be built recursively. If a property of a matcher is a function, it is evaluated.
*
* @see https://astexplorer.net/ to explore how ESTree nodes are structured
* @example nodeMatcher({type: `Identifier`, name: `foo`})(node)
*
* @param {Obj} matcher
* @param {Obj} refObj
* @param {string} refKey
@nojvek
nojvek / tron.ts
Created March 17, 2021 00:41
Tron Coding Challenge
enum GameState {
Undecided = 'undecided',
Draw = 'draw',
Player1Win = 'player1win',
Player2Win = 'player2win',
}
enum PlayerMark {
Blank = 0,
Player1 = 1,
@nojvek
nojvek / format-json.ts
Last active November 17, 2023 18:22
Json pretty printer that respects maximum line length
// @ts-ignore
import units from 'mdn-data/css/units.json';
const widgetSample = {
widget: {
debug: `on`,
window: {
title: `Sample Konfabulator Widget`,
name: `main_window`,
dimensions: {
@nojvek
nojvek / webpack-terser.js
Created January 15, 2020 19:21
webpack remove unused code options
const optimizationOptions = {
mode: PRODUCTION ? `production` : `development`,
module: {rules},
optimization: {
chunkIds: `named`,
moduleIds: PRODUCTION ? `hashed` : `named`,
usedExports: true,
minimize: PRODUCTION,
minimizer: [
new TerserPlugin({
@nojvek
nojvek / spa-nav.ts
Created January 14, 2020 23:33
spa-nav: navigation without page reload
// change document title to new app
document.title = newApp.title
// change the url without re-loading to the new app's url
if (ev.type !== `popstate`) {
// if we push on a popstate event, we break browser back button navigation, don't do that
window.history.pushState(``, ``, url);
}
// disable old css and add new css if not already loaded
@nojvek
nojvek / PerfMeasure.ts
Created January 14, 2020 22:36
Add marks and measures to performance timeline
const START = `start`;
const END = `end`;
export class PerfMeasure {
public measureName: string;
public started: boolean;
public ended: boolean;
constructor(measureName: string) {
this.measureName = measureName;
@nojvek
nojvek / side_by_side_urls.js
Created January 14, 2020 18:41
Loading two urls side by side.
/*
* 1) Install Chrome Split Tabs plugin: https://chrome.google.com/webstore/detail/split-tabs/mamepagkigmnpoalafajabnljlkkocbk
* 2) Run `/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222`
* 3) Load two about:blank tabs side by side when chrome starts
* 4) Start QuickTime and record screen with the two chrome tabs side by side
* 5) Run `node side_by_side_urls.js`, which loads two urls in both tabs simultaneously
*/
const puppeteer = require(`puppeteer`);
const fetch = require(`node-fetch`);
@nojvek
nojvek / webpackJsonp.js
Created November 23, 2019 00:46
webpackJsonp modules
moduleMap = {};
for (const p of webpackJsonp) {
const modules = p[1];
for (const [moduleName, moduleFn] of Object.entries(modules)) {
const moduleContent = moduleFn.toString();
const nameParts = moduleName.split(`!`);
const moduleId = nameParts[nameParts.length - 1] + (nameParts.length > 1 ? `!` : ``);
if (!moduleMap[moduleId]) {
moduleMap[moduleId] = moduleContent
} else if (moduleMap[moduleId] !== moduleContent) {