Skip to content

Instantly share code, notes, and snippets.

View bnoordhuis's full-sized avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
@bnoordhuis
bnoordhuis / count-promises.js
Created September 28, 2023 19:13
[node.js] count active promises via the V8 inspector
"use strict"
const inspector = require("node:inspector/promises")
const session = new inspector.Session()
session.connect()
countPromises(session).then(console.log)
async function countPromises(session) {
// resource management: put all results in an object group
const objectGroup = crypto.randomUUID()
@bnoordhuis
bnoordhuis / await.js
Created August 28, 2019 21:47
Await pending promises on Node.js process exit
// Copyright (c) 2019, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@bnoordhuis
bnoordhuis / bytestokey.js
Created November 29, 2017 22:55
Compute key+IV from passphrase (createCipher to createCipheriv migration script)
// Copyright (c) 2017, Ben Noordhuis <info@bnoordhuis.nl>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@bnoordhuis
bnoordhuis / uml-notes.md
Last active December 10, 2022 21:32
Setting up User Mode Linux on Fedora 20

user mode linux: build and run

Generate default .config.

$ make defconfig ARCH=um SUBARCH=x86_64

Build the linux ELF binary.

$ make -j8 linux ARCH=um SUBARCH=x86_64
diff --git a/src/unix/process.c b/src/unix/process.c
index c5a4592..59e1006 100644
--- a/src/unix/process.c
+++ b/src/unix/process.c
@@ -156,9 +156,14 @@ static int uv__process_init_pipe(uv_pipe_t* handle, int fds[2], int flags) {
return uv__make_pipe(fds, flags);
}
+#ifndef HAVE_VFORK
+# define HAVE_VFORK 1
@bnoordhuis
bnoordhuis / README.md
Created May 14, 2022 21:04
How to fix: unable to install (supposed) new info file /var/lib/dpkg/tmp.ci: Operation not permitted

A system crash at an inopportune time left my file system in a corrupted state. Fixing it up with fsck(1) worked just fine but made a subsequent system upgrade fail with an unusual error:

dpkg: error processing /var/cache/apt/archives/libfoo-1.2.3_amd64.deb (--unpack):
unable to install (supposed) new info file `/var/lib/dpkg/tmp.ci/symbols': Operation not permitted

The directory /var/lib/dpkg/tmp.ci did not exist. Creating it manually and re-running the upgrade failed exactly the same way (and removed the directory again.)

@bnoordhuis
bnoordhuis / http-and-https-proxy.js
Created February 8, 2013 16:31
A node.js proxy that accepts HTTP and HTTPS traffic on the same port.
var fs = require('fs');
var net = require('net');
var http = require('http');
var https = require('https');
var httpAddress = '/path/to/http.sock';
var httpsAddress = '/path/to/https.sock';
fs.unlinkSync(httpAddress);
fs.unlinkSync(httpsAddress);
@bnoordhuis
bnoordhuis / punycode.py
Created June 20, 2011 16:31
python punycode encoder and decoder
#!/usr/bin/env python
#
# Copyright (C) 2011 by Ben Noordhuis <info@bnoordhuis.nl>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@bnoordhuis
bnoordhuis / stacktrace.cc
Last active July 19, 2021 20:42
Decode C/C++ and V8 JS stack frames.
#include "v8.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <cxxabi.h>
#include <dlfcn.h>
using namespace v8;
@bnoordhuis
bnoordhuis / .vimrc
Created July 21, 2020 11:01
.vimrc
" vim > vi
set nocompatible
syntax on
filetype on
filetype plugin on
filetype indent on
" auto reload changes files (that don't have unsaved changes)
set autoread