Skip to content

Instantly share code, notes, and snippets.

@Conduitry
Conduitry / checkout_pr.sh
Last active January 9, 2024 16:54
Checkout PR, using GitHub API to determine what to track
#!/bin/sh
set -o errexit
[ $# != 1 ] && { >&2 echo 'Argument: <pull request id>'; exit 1; }
# Get origin remote
origin=$(git remote get-url origin)
# Find target ("owner/repo") of PR
temp=${origin#*github.com?}
[ $origin = $temp ] && { >&2 echo Unrecognized origin.; exit 1; }
@Conduitry
Conduitry / webpack_is_a_problem.md
Created June 17, 2019 15:36
webpack is a problem

webpack is a problem

Short version

This thing I said in a chat room one time:

webpack is so unknowable that everyone decided to give up on knowing their tools

Slightly less short version

@Conduitry
Conduitry / npml.sh
Created May 19, 2019 21:42
Easy simple npm linker
#!/bin/bash
if [ $# = 0 ]; then echo 'Arguments: <package>...'; exit 1; fi
DIR="$PWD"
for PKG in "$@"; do
BASE="$(basename "$PKG")"
while :; do
if [ -e node_modules/"$PKG" ]; then
DEST="$PWD"/node_modules/"$PKG"
while :; do
if [ -d "$BASE" ]; then
@Conduitry
Conduitry / http-request-helper.js
Last active November 3, 2018 11:54
Node.js http[s].request helper
// ClientRequest -> Promise<IncomingMessage> with an extra .body field that is a Buffer of the entire response
const response = request =>
new Promise((resolve, reject) =>
request
.once('response', response => {
const chunks = [];
response.on('data', chunk => chunks.push(chunk)).once('end', () => {
response.body = Buffer.concat(chunks);
resolve(response);
});
@Conduitry
Conduitry / async-local-context.js
Last active June 24, 2017 07:58
Async Local Context
// Async Local Context
// Requires Node.js nightly features and fixes, planned (I believe) to be released in 8.2.0
// Call `createContext()` to create a new local context.
// Call `getContext()` anywhere under that to retrieve the same local context.
// Call `createContext()` when there is already an existing context to create a new child context which inherits from the parent.
import { createHook, executionAsyncId } from 'async_hooks'

Keybase proof

I hereby claim:

  • I am conduitry on github.
  • I am conduitry (https://keybase.io/conduitry) on keybase.
  • I have a public key ASBpOMJeefTWfGUqRhYILq4Y3oQCeuU_H-a1cpsm7nagZQo

To claim this, I am signing this object:

@Conduitry
Conduitry / make-stream.js
Created September 5, 2016 22:32
Simple utility function for helping create gulp streams
import stream from 'stream'
let Transform = stream.Transform
export default function makeStream(transform, flush) {
let stream = new Transform({ objectMode: true })
let push = stream.push.bind(stream)
stream._transform = (file, enc, cb) => transform(file, push, cb)
if (flush) {
stream._flush = cb => flush(push, cb)
@Conduitry
Conduitry / promise-unhandled-rejection.js
Created September 5, 2016 22:31
Display warning messages in Node.js apps when rejected promises are not handled
let rejectionTimeouts = new WeakMap()
function displayError({ stack }) {
process.stderr.write(stack + '\n')
}
process.on('unhandledRejection', (err, promise) => {
rejectionTimeouts.set(promise, setTimeout(() => displayError(err), 200))
})
@Conduitry
Conduitry / replace-async.js
Created September 5, 2016 22:22
Asynchronous version of String.prototype.replace, using promises
export default function replaceAsync(str, re, func) {
let replacements = []
str.replace(re, (...args) => {
replacements.push(func(...args).then(res => [ args[args.length - 2], args[0].length, res ]))
})
return Promise.all(replacements).then(replacements => {
let out = ''
let lastEnd = 0
for (let [ offset, length, replacement ] of replacements) {
out += str.slice(lastEnd, offset) + replacement