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
@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 / 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 = () => {
#!/bin/bash
set -e
NAME=$1
[[ -z $NAME ]] && {
echo "Usage: $0 INSTANCE_NAME" >&2
exit 1
}
#!/bin/bash
set -e
region=${1:-us-east-1}
count=${2:-100}
aws --region $region elasticbeanstalk describe-application-versions |
jq -r '.ApplicationVersions[] | .ApplicationName + " " + .VersionLabel' |
head -$count |
#!/bin/bash
set -e
SELECTOR='string(//*[local-name()="entry"]/*[local-name()="title"][not(contains(text(), "beta"))])'
INSTALLED="dpkg-query -W -f '\${Version}' atom"
ARTIFACT='atom-amd64.deb'
INSTALL='sudo dpkg --skip-same-version --install'
version=$(