Skip to content

Instantly share code, notes, and snippets.

View timdp's full-sized avatar

Tim De Pauw timdp

View GitHub Profile
#!/bin/bash
set -euo pipefail
BOLD=$(tput bold)
DIM=$(tput dim)
YELLOW=$(tput setaf 3)
RESET=$(tput sgr0)
pr() {
@timdp
timdp / create-worker.js
Created April 4, 2021 21:48
AVA Shared Worker utils
const createDebug = require('debug')
const { serializeError } = require('serialize-error')
const receiveCommands = async (main, commands, debug) => {
for await (const message of main.subscribe()) {
if (message.data == null || typeof message.data.type !== 'string') {
debug('unexpected message', { message })
continue
}
const { type, payload } = message.data
<?php
//
// delete-old-tweets.php - https://github.com/timdp
//
// -- Instructions --
// 1. Save this script somewhere as delete-old-tweets.php
// 2. Get your Twitter archive and extract it to the same folder
// 3. Clone https://github.com/themattharris/tmhOAuth to the same folder
// 4. Register an app at dev.twitter.com and enter its credentials below
@timdp
timdp / serialize.js
Created June 29, 2020 13:18
YAMLish
const misleadingStrings = ['', 'true', 'false']
const reWhitespaceStart = /^\s/
const reWhitespaceEnd = /\s$/
const reNumeric = /^\s*(?:[0-9]+|[0-9]*\.[0-9]+)\s*$/
const indent = ' '
const maxStringLength = 60
const keysSorted = true
const byKey = (a, b) => a[0].localeCompare(b[0])
#!/bin/bash
set -euo pipefail
curl \
--silent \
"https://api.cloudflare.com/client/v4/zones" \
-H "X-Auth-Email: $CLOUDFLARE_EMAIL" \
-H "X-Auth-Key: $CLOUDFLARE_TOKEN" \
-H "Content-Type: application/json" |
const http = require('http')
const net = require('net')
const { performance } = require('perf_hooks')
const HOST = 'example.com'
const ADDRESS = '93.184.216.34'
const FAMILY = 4
let lookupCountCreateConnection = 0
let lookupCountSocketEvent = 0
const http = require('http')
const PORT = 8888
const REQUEST_LATENCY = 100
const REQUEST_COUNT = 1000
const requestOptions = {
hostname: '127.0.0.1',
port: PORT,
path: '/',
@timdp
timdp / retry.js
Created June 20, 2016 16:49
retry with async/await
import delay from 'delay'
const createAttempter = (worker) => async () => {
let retval, error, time
const startTime = Number(new Date())
try {
retval = await worker()
} catch (err) {
error = err
}
@timdp
timdp / list.sh
Created April 3, 2016 13:04
List npm dependents for all your packages
# Requirements:
# - curl
# - pup (https://github.com/ericchiang/pup)
# - npm-dependents (https://www.npmjs.com/package/npm-dependents)
curl -s 'https://www.npmjs.com/~timdp' | \
pup '.collaborated-packages a text{}' | \
xargs -n1 -I % sh -c 'echo -n %:\ ; npm-dependents % --list'
@timdp
timdp / proof.js
Created March 1, 2017 23:42
libxmljs memory leak
const libxmljs = require('libxmljs')
const doc = new libxmljs.Document()
const measure = () => {
global.gc()
return process.memoryUsage()
}
const run = () => {