Skip to content

Instantly share code, notes, and snippets.

View kentcdodds's full-sized avatar
🤓
working hard to make the world better with software

Kent C. Dodds kentcdodds

🤓
working hard to make the world better with software
View GitHub Profile
@kates
kates / search_and_replace.sh
Last active August 31, 2019 05:22
bulk search and replace with the silver searcher, awk, sed and xargs
ag "sometext" --nogroup | awk '{print substr($1,1,index($1,":")-1);}' | xargs -I {} sed -i .bak -e 's/sometext/anothertext/g' {}
@kentcdodds
kentcdodds / index.js
Created September 10, 2019 22:26
NodeJS file runner for Jest (create-node-runner using create-jest-runner). Use this with the runner option in jest config.
const {createJestRunner} = require('create-jest-runner')
module.exports = createJestRunner(require.resolve('./node-runner'))
@kentcdodds
kentcdodds / fix-feedback-links.js
Last active December 3, 2020 20:43
I use this to automatically fix links in my react workshops. (This one's only for the testing-react-apps repo because those markdown files aren't rendered in a UI, the normal one is at https://gist.github.com/kentcdodds/436a77ff8977269e5fee39d9d89956de)
@iansu
iansu / README.md
Last active March 1, 2021 08:40
Create React App 4.0 Alpha Testing

Create New App

JavaScript Template

npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app

TypeScript Template

npx create-react-app@next --scripts-version=@next --template=typescript@next my-ts-app

@kentcdodds
kentcdodds / README.md
Last active March 11, 2021 01:41
JavaScript Program Slicing with SliceJS

Route Module Pending Component Export

There are two primary approaches to page transitions (ignoring suspense's ditched attempt at a third)

  1. Indefinitely wait on the old screen
  2. Transition immediately to spinners/skeleton

Right now Remix has picked #1, but with a new export to a route module, we could support both.

Today, if you have this, Remix will wait for all data to load before displaying the page

@kentcdodds
kentcdodds / fix-links.js
Last active April 19, 2021 17:05
I use this to automatically fix links in my react workshops
@kentcdodds
kentcdodds / useOnRead.tsx
Last active June 9, 2021 04:24
How I determine whether you've read a blog post.
function useOnRead({
parentElRef,
onRead,
enabled = true,
}: {
parentElRef: React.RefObject<HTMLElement>
onRead: () => void
enabled: boolean
}) {
React.useEffect(() => {
@kentcdodds
kentcdodds / index.html
Last active June 24, 2021 19:48
The one true react boilerplate
<body>
<div id="⚛️"></div>
<script src="https://unpkg.com/react@16.0.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.0.0/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script>
<script type="text/babel">
ReactDOM.render(<div>Hello World!</div>, document.getElementById('⚛️'))
</script>
</body>
@kentcdodds
kentcdodds / add-discord-role.js
Last active August 21, 2021 16:29
An example of how you can add a role to a user with discord.js
const Discord = require('discord.js')
// your bot token
const token = 'NzM4MDk2NjA4NDQwNDgzODcw.XyG8CA.RbwIBFnAbrRDYOlTdLYgG_T4CMk'
const discordUsername = 'example#1234'
const roleToAdd = 'Cool Person'
const guildName = 'Your Guild Name'
function deferred() {
let resolve, reject