Skip to content

Instantly share code, notes, and snippets.

View mcollina's full-sized avatar

Matteo Collina mcollina

View GitHub Profile
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);
@mcollina
mcollina / principles.md
Last active May 18, 2023 18:27
Matteo's Technical principles

Matteo Technical Principles

1. Conway’s Law is paramount.

Any organization that designs a system (defined broadly) will produce a design whose structure is a copy of the organization's communication structure.

In order to design a piece of software we need to “design” the team that is going to produce it.

2. Developer Experience is key to productivity

@mcollina
mcollina / exhaust.mjs
Last active May 19, 2021 21:48
merge ensuring that all generators are fully consumed
import { setTimeout } from 'timers/promises'
import { strictEqual } from 'assert'
let called = 0
async function * merge (a, b) {
try {
yield *a
yield *b
} finally {
@mcollina
mcollina / tap-15.sh
Last active April 6, 2021 08:24
Remove all tap@15 deprecations
#!/bin/sh
find ./test -regex '.*js' | xargs sed -I '' 's/tearDown/teardown/g'
find ./test -regex '.*js' | xargs sed -I '' 's/strictEqual/equal/g'
find ./test -regex '.*js' | xargs sed -I '' 's/deepEqual/same/g'
find ./test -regex '.*js' | xargs sed -I '' 's/false(/notOk(/g'
find ./test -regex '.*js' | xargs sed -I '' 's/notStrictEqual/not/g'
find ./test -regex '.*js' | xargs sed -I '' 's/similar/match/g'
find ./test -regex '.*js' | xargs sed -I '' 's/strictDeepEqual/strictSame/g'
find ./test -regex '.*js' | xargs sed -I '' 's/is(/equal(/g'
find ./test -regex '.*js' | xargs sed -I '' 's/throw(/throws(/g'
'use strict'
const {
graphql,
parse,
buildSchema,
extendSchema,
buildASTSchema
} = require('graphql')
exports.notification = (req, res, next) => {
const notificationPayload = {
notification: {
title: 'Blogial new post',
body: req.body.title,
icon: 'assets/icons/icon-512x512.png'
}
};
Subscription.find()
.then(subscriptions => {
'use strict'
const { Readable, finished } = require('stream')
const { promisify } = require(util)
async function run (origin, dest) {
try {
const write = buildWrite(dest)
// This is an async iterator
for await (let chunk of origin) {
const http2 = require('http2');
const options = {
key: getKeySomehow(),
cert: getCertSomehow()
};
// https is necessary otherwise browsers will not
// be able to connect
const server = http2.createSecureServer(options, (req, res) => {
res.end('Hello World!');
@mcollina
mcollina / summit.md
Last active February 26, 2018 14:04
Collaborato Summit - May 31st - June 1st 2018, Berlin

Collab Summit Berlin 2018

We are back with the date for the Node.js Collaborator Summit in Berlin next to JSConf.Eu (which is on June 2-3, 2018). This is a live issue that will be constantly updated to match the proposed agenda.

Collaborator Summit Day One: May 31st, 2018

AWS Berlin address TBD 10am-6pm