Skip to content

Instantly share code, notes, and snippets.

@tsmx
tsmx / got-download-stream.js
Last active October 6, 2022 13:40
Stream-download a file with filename from response header (content-disposition) via got package.
const got = require('got');
const stream = require('stream');
const fs = require('fs');
const { promisify } = require('util');
const pipeline = promisify(stream.pipeline);
// instantiate the download stream - use options to set authorization header etc. if needed
let downStream = got.stream('https://example.com/download');
downStream.on('response', response => {
@ali-kamalizade
ali-kamalizade / healthcheck.js
Last active September 18, 2024 14:57
A sample implementation of a health check endpoint for Node.js using Express
// app.js: register the route. In our case, we don't want authorization for this route
app.use('/healthcheck', require('./routes/healthcheck.routes'));
// healthcheck.routes.js: return a 2xx response when your server is healthy, else send a 5xx response
import express from 'express';
const router = express.Router({});
router.get('/', async (_req, res, _next) => {
// optional: add further things to check (e.g. connecting to dababase)
@OllieJones
OllieJones / queue.js
Last active September 17, 2021 15:50
Queue class, super simple, based on Kate Morley's queue code.
'use strict';
/*
Queue.js
A class to represent a queue
Created by Kate Morley - https://code.iamkate.com/ - and released under the terms
of the CC0 1.0 Universal legal code:
@winguse
winguse / Tenda U9 on linux.md
Last active October 20, 2023 09:40
Tenda U9 on linux

Two files:

  • /etc/usb_modeswitch.d/rtl8821cu
  • /usr/share/usb_modeswitch/0bda:1a2b
TargetVendor=0x0bda
TargetProduct=0x1a2b
StandardEject=1
@keepitsimple
keepitsimple / ip4.js
Last active August 8, 2018 14:40
JavaScript the best RegEx for IPv4 validation with test examples
const ip4RegEx = /^(?:(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\.(?!$)|$)){4}$/
/*
//valid
127.0.0.1
192.168.1.1
192.168.1.255
255.255.255.255
0.0.0.0
1.1.1.1
@swalkinshaw
swalkinshaw / tutorial.md
Last active November 13, 2023 08:40
Designing a GraphQL API
@ivan-loh
ivan-loh / install-watchman.sh
Last active January 27, 2022 13:02
Watchman ( 4.9.0 ) installation for Ubuntu 16.04
# checkout, compile & install
git clone https://github.com/facebook/watchman.git
cd watchman/
git checkout v4.9.0
sudo apt-get install -y autoconf automake build-essential python-dev libssl-dev libtool
./autogen.sh
./configure
make
sudo make install
@mifix
mifix / resize.sh
Created May 30, 2016 09:33
LXD - ZFS - resize
# make sure zfs autoexpand is enabled (only needed once)
sudo zpool set autoexpand=on lxd
sudo truncate -s 50G /var/lib/lxd/zfs.img
# Make zfs realize the fact that partition has been changed and make zpool
# use the new partition which is actually the same one
sudo zpool online -e lxd /var/lib/lxd/zfs.img /var/lib/lxd/zfs.img
@waaaaargh
waaaaargh / multiple-processes
Last active February 12, 2018 17:32
[Draft] This document explains how to run multiple tor processes on one host.
Managing multiple Tor processes on one host
===========================================
Due to Tor's internal architecture, running only one Tor process per physical
host is often not enough. As a thumb rule, you should run one Tor process per
physical CPU core to make full use of the host's CPU power. This, however
brings with it other difficulties: The tor network limits the number of Tor
relays per IP in the consensus to 2. Also, the relay nodes should be rechable
on Port 80 and 443 since those ports are often unfiltered and unblocked.
@plentz
plentz / nginx.conf
Last active September 16, 2024 17:52
Best nginx configuration for improved security(and performance)
# to generate your dhparam.pem file, run in the terminal
openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048