Skip to content

Instantly share code, notes, and snippets.

View mcollina's full-sized avatar

Matteo Collina mcollina

View GitHub Profile
@mcollina
mcollina / go.js
Created August 18, 2023 15:36 — forked from cjihrig/go.js
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() {
@mcollina
mcollina / .tmux.conf
Created August 7, 2023 16:08
My tmux.conf
# set-option -g default-command "reattach-to-user-namespace -l /bin/bash"
set -g default-terminal "screen-256color"
# Pane resizing
bind -r H resize-pane -L 5
bind -r J resize-pane -D 5
bind -r K resize-pane -U 5
bind -r L resize-pane -R 5
# splitting panes
const pinoStdSerializers = require('pino-std-serializers')
const logger = require('pino')({
serializers: {
error: pinoStdSerializers.err
}
})
try {
throw new Error('kaboom')
} catch (error) {
import { createServer } from 'http'
import { connect } from 'net'
const server = createServer(function (req, res) {
console.log('request!')
server.close()
res.setHeader('Connection', 'close')
res.end('hello world')
})
@mcollina
mcollina / publish.sh
Created August 12, 2022 22:22
npm workspace publish
#!/bin/sh
VERSION=$1
MODULES=`node -e "console.log(require('./package.json').workspaces.join(' '))"`
for MODULE in $MODULES; do
echo "Building $MODULE"
pushd $MODULE
npm version $VERSION --save
NAME=`node -e "console.log(require('./package.json').name)"`
// Run this with npx jest globals-jest-problem.test.js
// This is because of https://github.com/facebook/jest/issues/2549
const assert = require('assert')
test('assert', () => {
try {
assert.strictEqual(2, 3)
} catch (err) {
// This will fail
@mcollina
mcollina / sponsor-nodeland.md
Last active May 23, 2022 10:13
Sponsor Adventures in Nodeland

Last updated: May 2022


TL.DR:

  • 1700+ subscribers
  • Qualified and engaged audience that like receiving my emails
npm i fastify@next
import Fastify from 'fastify'
const app = Fastify({ logger: true })
app.get('/', async (request, reply) => {
setImmediate(() => {
reply.send({ hello: 'world' })
})
// return reply is needed to tell Fastify we will call
// reply.send() in the future.
@mcollina
mcollina / error.js
Last active March 21, 2022 15:50
Error keep things from collecting
// Taken from https://twitter.com/robpalmer2/status/1505881530379419652?s=20&t=rNQb26Rwq0fddQHbhalpbw
function test() {
const lotsOfMemory = new Uint8Array(1000 * 1000 * 100);
function retains() { lotsOfMemory }
const someNumber = Math.random();
setInterval(() => {
console.log(someNumber);
}, 1000);