Skip to content

Instantly share code, notes, and snippets.

View lencioni's full-sized avatar

Joe Lencioni lencioni

  • Airbnb
  • Northfield, Minnesota, USA
  • X @lencioni
View GitHub Profile
@lencioni
lencioni / tarjan.test.ts
Last active July 8, 2022 16:07
Tarjan's strongly connected components algorithm in TypeScript. Adapted from https://gist.github.com/chadhutchins/1440602
import { Graph, Vertex, Tarjan } from '../tarjan';
it('handles simple cases', () => {
const v0 = new Vertex('0');
const v1 = new Vertex('1');
const v2 = new Vertex('2');
v0.connections.add(v1);
v1.connections.add(v2);
@lencioni
lencioni / css-perf-metrics.csv
Created May 20, 2022 17:31
Comparison of perf metrics of various libraries
react-with-styles (control) Emotion Treat Linaria
Total Blocking Time (ms) 276 189 (-87) 122 (-154) 144 (-132)
JS bundle size (KiB) 666 677 (+11) 581 (-85) 596 (-70)
CSS bundle size (KiB) 8 8 (+0) 12 (+4) 13 (+5)
Update layout tree count 2.84 2.96 (+0.12) 2.00 (-0.84) 2.00 (-0.84)
Update layout tree duration (ms) 7,594 3,225 (-4,369) 3,313 (-4,281) 3,380 (-4,214)
Composite layers count 5.43 5.22 (-0.21) 4.05 (-1.38) 4.04 (-1.39)
Composite layers duration (ms) 660 379 (-281) 306 (-354) 292 (-368)
@lencioni
lencioni / tsserverWithEventsPlugin.ts
Last active May 20, 2021 15:59
TypeScript Server Plugin with custom project event handler
import * as ts_module from 'typescript/lib/tsserverlibrary';
/** Log to the TS Server log */
function log(info: ts.server.PluginCreateInfo, message: string) {
info.project.projectService.logger.info(`[My TS Server Plugin] ${message}`);
}
// https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin
export default function init({ typescript: ts }: { typescript: typeof ts_module }) {
return {
@lencioni
lencioni / pi.js
Created March 14, 2021 20:51
Calculate pi
// See "Unbounded Spigot Algorithms for the Digits of Pi," by Jeremy Gibbons,
// Math. Monthly, April 2006, pages 318-328.
// Adapted from https://gustavus.edu/mcs/max/pi/
let app;
let q = BigInt(1);
let r = BigInt(0);
let t = BigInt(1);
let k = BigInt(1);
@lencioni
lencioni / waitUntilSettled.ts
Last active October 20, 2023 14:43
cy.waitUntilSettled()
/**
* We often run into a problem with functions that select DOM nodes like
* `cy.get`, where in between the `cy.get` call and the next item in the chain,
* the DOM element that `cy.get` found ends up being removed from the DOM. This
* can affect code as simple as:
*
* cy.get('button').click();
*
* When it fails sporadically, it uses the following error message:
*
@lencioni
lencioni / array.includes.js
Last active February 17, 2020 14:01
Webpack module replacements for shims/polyfill packages
module.exports = function arrayIncludes(arr, search, fromIndex) {
return arr.includes(search, fromIndex);
};
@lencioni
lencioni / propTypes.diff
Created August 22, 2018 22:25
react-dates propTypes removal diff
diff -bur esm-before/components/CalendarDay.js esm/components/CalendarDay.js
--- esm-before/components/CalendarDay.js 2018-08-22 15:21:46.000000000 -0700
+++ esm/components/CalendarDay.js 2018-08-22 15:22:02.000000000 -0700
@@ -25,7 +25,7 @@
import { DAY_SIZE } from '../constants';
-var propTypes = forbidExtraProps(_objectAssign({}, withStylesPropTypes, {
+var propTypes = process.env.NODE_ENV !== "production" ? forbidExtraProps(_objectAssign({}, withStylesPropTypes, {
day: momentPropTypes.momentObj,
@lencioni
lencioni / dynamic-import-requires-webpack-chunkname-test.js
Last active March 22, 2018 16:03
dynamic-import-requires-webpack-chunkname ESLint rule
/**
* @fileoverview dynamicImport requires a leading comment with the webpackChunkName
* @author Kimberly Strauch
* @copyright 2018 Kimberly Strauch. All rights reserved.
* See LICENSE file in root directory for full license.
*/
'use strict';
const rule = require('../../../lib/rules/dynamic-import-requires-webpack-chunkname');
@lencioni
lencioni / find-nearly-empty-directories.sh
Created August 31, 2017 17:10
Script to help find nearly empty directories
#!/bin/sh
# Find directories that only contain a single .eslintrc file.
# Adapted from https://superuser.com/a/727070
# Enable double glob to find hidden files
shopt -s dotglob
# Loop through every subdirectory.
# Currently need to tweak this line and run it for every level of directory
@lencioni
lencioni / story.js
Created May 18, 2017 20:17
Building Storybook stories with allExamples.js
import { storiesOf, action } from '@kadira/storybook';
import { browserDLSExamples } from '../examples/allExamples';
import fixtures from '../examples/fixtures';
const { DLSExamples, DLSComponents } = browserDLSExamples();
Object.entries(DLSExamples).forEach(([name, examplesFunc]) => {
let story = storiesOf(name, module);