Skip to content

Instantly share code, notes, and snippets.

Working from home

Jonathan Creamer jcreamer898

Working from home
View GitHub Profile
View tweet-when-to-use-generators-iterators.js
// Builds array of everything ahead of time
function collectAllItems() {
return [calculateFirst(), calculateSecond(), ...]
// This loop will end as soon as `isMatch(item)` is truthy.
// If the very first item in the array is a match, then we
// wasted all this time building the array in the first place.
for (let item of collectAllItems()) {
if (isMatch(item)) {
Rich-Harris /
Last active Oct 12, 2020
Don't ship untranspiled code

When Babel 6 came out, it was hard for a lot of packages to upgrade because it was essentially an entirely different category of thing than Babel 5. So what happened was that some packages upgraded, and some didn't — at least not straight away.

Some projects took the prima facie enlightened view that packages should expose untranspiled code, so that the consumers of that code could determine for themselves what needed to get transpiled based on the environments they supported.

That was a costly decision. If I was the author of an app that was using Babel 6, I couldn't import a library that was still using Babel 5 and shipping untranspiled code (because the configs were completely incompatible), and vice versa. Frankly, it was a bloody nuisance. We are bad at anticipating these sorts of issues. It will happen again at some point.

Adding a few extra bytes to pkg.main or pkg.module is a small price to pay for things just working. As well as avoiding the aforementioned headaches, it means that your

stefanbuck /
Last active Apr 29, 2021
Script to upload a release asset using the GitHub API v3.
#!/usr/bin/env bash
# Author: Stefan Buck
# License: MIT
# This script accepts the following parameters:
# * owner
acdlite / app.js
Last active Jan 7, 2021
Quick and dirty code splitting with React Router v4
View app.js
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
gaearon / connect.js
Last active May 10, 2021
connect.js explained
View connect.js
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
View webpack.config.js
const webpack = require('webpack')
const Configs = require('react-project/webpack')
test: /modules\/client-only\//,
loader: 'null-loader'
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/)
DarrenN / get-npm-package-version
Last active May 15, 2021 — forked from yvele/get-npm-package-version
Extract version from package.json (NPM) using bash / shell
View get-npm-package-version
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
Joris-van-der-Wel / v8-profiler.js
Last active Dec 7, 2020
node.js profiling: generate .cpuprofile which can be opened in chrome dev tools (F12)
View v8-profiler.js
'use strict';
var profiler = require('v8-profiler');
// ...
var cpuProfile = profiler.stopProfiling();
require('fs').writeFileSync(__dirname + '/foo.cpuprofile', JSON.stringify(cpuProfile));
vsouza / .bashrc
Last active May 9, 2021
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
View .bashrc
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin