Skip to content

Instantly share code, notes, and snippets.

View nckcol's full-sized avatar
💩
lets get shit done

Nikita Popov nckcol

💩
lets get shit done
View GitHub Profile
@PabloSzx
PabloSzx / test-esm.mjs
Created August 12, 2021 16:45
Quick test Node.js ESM
// Using:
// globby@11.0.4
// chalk@4.1.2
import globby from 'globby';
import { dirname } from 'path';
import { fileURLToPath } from 'url';
import chalk from 'chalk';
async function main() {
@sindresorhus
sindresorhus / esm-package.md
Last active May 6, 2024 13:26
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@andrewcourtice
andrewcourtice / task.ts
Last active April 21, 2024 09:08
Async cancellation using promise extension and abort controller
/*
This a basic implementation of task cancellation using a Promise extension
combined with an AbortController. There are 3 major benefits to this implementation:
1. Because it's just an extension of a Promise the Task is fully
compatible with the async/await syntax.
2. By using the abort controller as a native cancellation token
fetch requests and certain DOM operations can be cancelled inside the task.
3. By passing the controller from parent tasks to new child tasks an entire
async chain can be cancelled using a single AbortController.
@queq1890
queq1890 / main.ts
Last active May 27, 2023 01:55
Create a new pull request with empty commit using @octokit/rest
import { Octokit } from '@octokit/rest';
type Option = {
owner: string;
repo: string;
baseBranch: string;
newBranch: string;
pullRequest: {
title: string;
body: string;
@colinhacks
colinhacks / _document.tsx
Last active January 12, 2023 16:44
How to support server-side rendering for plain "emotion" package in Next.js
// ⚠️ works with Emotion 10 only! ⚠️
// 1. `yarn add emotion-server`
// 2. copy the contents of this file into your `pages` directory
// 3. save it as `_document.tsx`
// should work out of the box
import Document, { Head, Main, NextScript } from 'next/document';

babel-plugin-transform-mui-imports npm

A plugin to make authoring with MUI components efficient, both for humans and bundlers.

Here's why:

@sorenlouv
sorenlouv / useComponentId.js
Last active June 16, 2023 15:26
React hook for getting a unique identifier for a component
import { useRef } from 'react';
let uniqueId = 0;
const getUniqueId = () => uniqueId++;
export function useComponentId() {
const idRef = useRef(getUniqueId());
return idRef.current;
}
@amnox
amnox / injectReducer.js
Created March 25, 2019 10:18
A demo implementation of Reducer Injection is React
import React from 'react';
import PropTypes from 'prop-types';
import hoistNonReactStatics from 'hoist-non-react-statics';
import invariant from 'invariant';
import isEmpty from 'lodash/isEmpty';
import isFunction from 'lodash/isFunction';
import isString from 'lodash/isString';
import checkStore from './checkStore';
import createReducer from '../reducers';
import conformsTo from 'lodash/conformsTo';
@ServerlessBot
ServerlessBot / IAMCredentials.json
Last active December 20, 2023 16:50
Minimum credential set for Serverless Framework
{
"Statement": [
{
"Action": [
"apigateway:*",
"cloudformation:CancelUpdateStack",
"cloudformation:ContinueUpdateRollback",
"cloudformation:CreateChangeSet",
"cloudformation:CreateStack",
"cloudformation:CreateUploadBucket",
@bvaughn
bvaughn / index.md
Last active May 4, 2024 11:25
How to use profiling in production mode for react-dom

React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.

Table of Contents

Profiling in production

React DOM automatically supports profiling in development mode for v16.5+, but since profiling adds some small additional overhead it is opt-in for production mode. This gist explains how to opt-in.