Skip to content

Instantly share code, notes, and snippets.

@cjihrig
cjihrig / go.js
Created August 18, 2023 15:02
Parse Node Download Data
'use strict';
const assert = require('node:assert');
const fs = require('node:fs/promises');
const DATA_HOME_URL = 'https://storage.googleapis.com/access-logs-summaries-nodejs/index.html';
const DATA_FILE_PATH = 'data.json';
const DATA_CSV_PATH = 'data.csv';
const DATA_CSV_SEVEN_DAY_PATH = 'data-seven-day-avg.csv';
const LINES = ['14', '16', '18', '19', '20'];
async function main() {
@cjihrig
cjihrig / why-assert.md
Created December 31, 2019 20:42
On Using `assert` as Your Assertion Library

This gist is a more detailed followup to this tweet in which I advocate for using Node's assert module as your goto assertion library.

Not Hatin', Just Sayin' Disclaimer: There are plenty of perfectly good JavaScript assertion libraries out there. If you're happy with your current choice in assertion libraries, please continue using them. This gist is just my personal opinion. It does not represent the opinion of my employer, your employer, or anyone else.

Background

@cjihrig
cjihrig / wasi.c
Last active March 21, 2020 14:14
WASI C Header
#include "uvwasi.h"
__wasi_errno_t __wasi_args_get(char** argv, char* argv_buf) {
return __WASI_ENOTSUP;
}
__wasi_errno_t __wasi_args_sizes_get(size_t* argc, size_t* argv_buf_size) {
return __WASI_ENOTSUP;
@cjihrig
cjihrig / README libvirt cloud-init with static networking.md
Created February 14, 2019 20:22 — forked from itzg/README libvirt cloud-init with static networking.md
Configuring a libvirt domain with a static IP address via cloud-init local datasource

Here is how to create a cloud-init disk image and OS disk image suitable for configuring into a libvirt domain file.

In my case I am naming my domain (a.k.a. virtual machine or VM) xenial with a static IP address of 192.168.0.101. The filenames "network-config" and "user-data" files are arbitrary, so they can be named with a prefix for the domain, etc.

First, get the cloud image and convert into QCOW2 format:

qemu-img convert -O qcow2 xenial-server-cloudimg-amd64-disk1.img xenial-server-cloudimg-amd64-disk1.qcow2

Challenges in using post-mortem debugging with async/await

Introduction

async/await is a new feature of the EcmaScript programming language that combines generators and promises to improve the language-level model for writing asynchronous code.

It is [currently in "stage 3"](https://github.com/tc39/ecma262#current- proposals) of the TC39 process,

@cjihrig
cjihrig / README.md
Created November 11, 2016 20:21 — forked from renchap/README.md
One-line certificate generation/renews with Letsencrypt and nginx

Prerequisites : the letsencrypt CLI tool

This method allows your to generate and renew your Lets Encrypt certificates with 1 command. This is easily automatable to renew each 60 days, as advised.

You need nginx to answer on port 80 on all the domains you want a certificate for. Then you need to serve the challenge used by letsencrypt on /.well-known/acme-challenge. Then we invoke the letsencrypt command, telling the tool to write the challenge files in the directory we used as a root in the nginx configuration.

I redirect all HTTP requests on HTTPS, so my nginx config looks like :

server {
@cjihrig
cjihrig / keybase.md
Created July 23, 2015 01:59
keybase.md

Keybase proof

I hereby claim:

  • I am cjihrig on github.
  • I am cjihrig (https://keybase.io/cjihrig) on keybase.
  • I have a public key whose fingerprint is 94AE 3667 5C46 4D64 BAFA 68DD 7434 390B DBE9 B9C5

To claim this, I am signing this object:

build

Clone and build Node for analysis:

$ git clone https://github.com/joyent/node.git
$ cd node
$ export GYP_DEFINES="v8_enable_disassembler=1"
$ ./configure
$ make -j4
@cjihrig
cjihrig / v8.md
Last active August 29, 2015 14:16 — forked from kevincennis/v8.md

Installing V8 on a Mac

Prerequisites

  • Install Xcode (Avaliable on the Mac App Store)
  • Install Xcode Command Line Tools (Preferences > Downloads)

Build V8

  • git clone git@github.com:v8/v8.git
@cjihrig
cjihrig / mdb.md
Last active August 29, 2015 14:06 — forked from tjfontaine/mdb.md

MDB is unlike most debuggers you've experienced.

It is not a source level debugger like gdb or lldb or even Node's builtin debugger

Generally used for postmortem analysis.

Postmortem is for Production and Development

We operate mostly on core files, though you can attach to running processes as well.