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 / AsyncComponent.jsx
Created January 8, 2017 17:09
<AsyncComponent> at Airbnb used for Webpack code splitting
// Usage:
//
// function loader() {
// return new Promise((resolve) => {
// if (process.env.LAZY_LOAD) {
// require.ensure([], (require) => {
// resolve(require('./SomeComponent').default);
// });
// }
// });
@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 / us-states-simplified.json
Last active March 9, 2018 19:30
US states without counties TopoJSON
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lencioni
lencioni / find-dead-js-modules.sh
Last active June 26, 2017 18:51 — forked from trotzig/find-dead-js-modules.sh
This script will find javascript modules that aren't currently used in your application.
#!/bin/bash
# Make the script fail on the first error encountered.
set -euo pipefail
# Create a temp folder that we can use to store files in.
if [ "$(uname -s)" = "Darwin" ]; then
tmp_dir=$(mktemp -d -t find-dead-modules.XXXXXXXX)
else
tmp_dir=$(mktemp -d --tmpdir find-dead-modules.XXXXXXXX)
@lencioni
lencioni / Button_example.jsx
Last active May 18, 2017 20:57
Button example file
import React from 'react';
export default ({ Button }, { action, fixtures }) => ({
// Optional property that can be used to mark related components in Storybook
tags: ['tag1', 'tag2'],
// Optional property for some Markdown that will show up in the Usage tab in
// Storybook
usage: `
Button documentation in Markdown.
@lencioni
lencioni / allExamples.js
Created May 18, 2017 20:17
Slurping up all examples and components with webpack
// Keep track of all DLS components:
const DLSComponents = {};
// Keep track of all DLS examples:
const DLSExamples = {};
function requireComponent(srcFile, requireFn) {
// Extract the component name from the file name:
let componentName = path.basename(srcFile, '.jsx');
// Handle ComponentName/index.jsx:
@lencioni
lencioni / jsx.snippets
Last active August 29, 2016 18:08
React.js createClass snippet
snippet cc "createClass" b
var ${1:`!p snip.rv = ''.join(x.title() for x in re.sub('\.js$', '', snip.basename or 'ModuleName').split('_'))`} = React.createClass({
/**
* @return {Object}
*/
render: function() {
return (
$0
);
}
@lencioni
lencioni / countTests.sh
Last active May 31, 2016 21:37
Count the number of JavaScript tests in a git repo every day
#!/bin/bash
echo '"days ago","tests"' > testCounts.csv
for i in $(seq 1 365);
do
git checkout "$(git rev-list -n 1 --before="$i days ago" origin/master)"
matches=$(\
find spec/javascripts -name "*.js" -o -name "*.jsx" | \