This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useMatchMedia(query) { | |
const mediaQuery = useMemo(() => window.matchMedia(query), [ query ]); | |
const [ matches, setMatches ] = useState(mediaQuery.matches); | |
useEffect(() => { | |
function onChange({ matches: newMatches }) { | |
setMatches(newMatches); | |
} | |
if (mediaQuery.addEventListener) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Throttles an async function. | |
function throttleAsync(fn, wait) { | |
let lastRun = 0; | |
let currentRun = null; | |
async function throttled(...args) { | |
if (currentRun) | |
return currentRun; | |
const currentWait = lastRun + wait - Date.now(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Concurrently transform a MongoDB cursor into a stream of bulk MongoDB updates. | |
// | |
// Usage: | |
// | |
// const users = db.collection('users'); | |
// const usersToUpdate = users.find({ email: null }); | |
// | |
// await eachAsyncUpdate(users, usersToUpdate, async function(user) { | |
// const userEmail = await findUserEmail(user); | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AL America/Chicago | |
AK America/Anchorage | |
AS Pacific/Samoa | |
AZ America/Denver | |
AR America/Chicago | |
CA America/Los_Angeles | |
CO America/Denver | |
CT America/New_York | |
DE America/New_York | |
DC America/New_York |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Monitors your tree and runs tests when anything changes. | |
# | |
# `make`, `yarn test`, etc. automatically detected. | |
# | |
# $ autotest | |
# | |
# Run a specific command on changes: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Monitors your tree and runs tests when anything changes. | |
# | |
# `make`, `yarn test`, etc. automatically detected. | |
# | |
# $ autotest | |
# | |
# Run a specific command on changes: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Monitors your tree and runs tests when anything changes. | |
# | |
# `make`, `yarn test`, etc. automatically detected. | |
# | |
# $ autotest | |
# | |
# Run a specific command on changes: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Mongoose = require('mongoose'); | |
Mongoose.Promise = Promise; | |
Mongoose.connect(`mongodb://localhost/test-${Date.now()}`); | |
const PersonSchema = new Mongoose.Schema({ | |
name: { | |
first: { type: String }, | |
last: { type: String } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# `nvm use` the version specified in package.json. | |
source $(brew --prefix nvm)/nvm.sh | |
set -eo pipefail | |
die() { | |
echo "$@" >&2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Monitors your tree and runs tests when anything changes. | |
# | |
# Run `make`, `npm test`, etc. automatically detected. | |
# | |
# $ autotest | |
# | |
# Run a specific command on changes: | |
# |
NewerOlder