Skip to content

Instantly share code, notes, and snippets.

View thlorenz's full-sized avatar
👁️
{ this.props.status }

Thorsten Lorenz thlorenz

👁️
{ this.props.status }
View GitHub Profile
@thlorenz
thlorenz / keybase.md
Last active June 11, 2019 19:14
keybase.md

Keybase proof

I hereby claim:

  • I am thlorenz on github.
  • I am thlorenz (https://keybase.io/thlorenz) on keybase.
  • I have a public key ASDi53IJKgU2P7pjH8Aepd3pnhwCfFWfL7s7VHVBAuHPMwo

To claim this, I am signing this object:

@thlorenz
thlorenz / sample.js
Last active February 26, 2019 03:56
Why is fs.createReadStream always emitting buffers? Read the comment and corrected sample to find the answer ;)
var stream = require('stream');
var util = require('util');
var Writable = stream.Writable;
module.exports = CheckEncodingWritable;
util.inherits(CheckEncodingWritable, Writable);
function CheckEncodingWritable (opts) {
@thlorenz
thlorenz / _obs-settings-slow-internet.md
Last active November 24, 2018 02:24
[settings] OBS settings for streaming with not so great internet

OBS Low Internet Settings

These were provided to me by @feross at some point and then I tweaked them to work with slow internet, i.e. 1MBPS up.

I'm posting the the screenshots of those settings in the comments and I added two files that I found via File/Show Profile Folder

@thlorenz
thlorenz / Reusing Errors vs. creating new Error with stack attached.md
Last active August 26, 2018 15:12
Reusing Errors vs. creating new Error with stack attached

It is not usually recommended to reuse errors since the stack trace is attached whenever the error is instantiated.

However in some cases the overhead of doing that may affect performance, especially if the error is an exception that is known to occur frequently and is handled.

Only in these cases it may be advantagous to reuse the created Error. In all other cases getting a full stacktrace created at the time the exception occurs is to be preferred as it gives much better information needed to debug the problem.

Run

➝ node errors.js
@thlorenz
thlorenz / async-wrap-express-wrapper.md
Last active August 26, 2018 15:09
async/wrap express wrapper

Summary

Tried to improve debugging when an express middleware is wrapped to auto-handle errors of an asnync function.

Turns out the below reads a bit better than a return Promise.catch() implementation, but still, once we reach the central express error handler, the line of the wrapped function that caused the error isn't included.

Implementation

'use strict'
@thlorenz
thlorenz / .generating-xcode-via-gyp.md
Last active August 26, 2018 15:05
Generating Xcode projects from Node.js binding repos via gyp

This is specifically tailored to Node.js binding projects in which case the C++ layer is always a library.

Clone gyp:

git clone --depth 1 https://chromium.googlesource.com/external/gyp.git gyp

Add the below common.gypi file in the root of the project.

@thlorenz
thlorenz / deoptmark.js
Last active August 13, 2018 20:37
Provide benchmark.js interface to just run functions meant to be benchmarked, i.e. to collect deoptimization info
'use strict'
const deferred = {
resolve: function dontCare() {}
}
class DeoptMark {
constructor({ ITER = 1E3 } = {}) {
this._ITER = ITER
this._fns = []
@thlorenz
thlorenz / Understanding why the new V8 is so Damn Fast, One Demo at a Time.md
Last active May 23, 2018 17:15
[tallk] Understanding why the new V8 is so Damn Fast, One Demo at a Time

Understanding why the new V8 is so Damn Fast, One Demo at a Time

Abstract

The entire V8 compiler architecture as well as large parts of the Garbage Collector where updated recently. TurboFan replaced Crankshaft, Orinoco now collects garbage in parallel whenever possible. Node.js v8 shipped with this new and improved version of V8. As a result we can finally write idiomatic and declarative JavaScript without worrying about incurring performance overhead due to JavaScript compiler shortcomings.

At least this is what the V8 team tells us. In this talk we will explore if and why this is true, one demo at a time.

@thlorenz
thlorenz / clean-dupes.js
Created February 22, 2017 19:27
Remove duplicate files found inside one directory
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
function bySizeThenByName(a, b) {
if (a.size === b.size) {
return a.path.localeCompare(b)
}
return a.size < b.size
@thlorenz
thlorenz / update_to_nan_v2.0.x.sh
Last active October 13, 2016 08:04
Script to update Node.js addons to work with nan 2.0.x and thus with iojs v3.x (gets you 90% there)
#!/bin/bash
replacements=(
"NanAsyncWorker/Nan::AsyncWorker"
"NanAsyncQueueWorker/Nan::AsyncQueueWorker"
"NanCallback/Nan::Callback"
"NanSetInternalFieldPointer/Nan::SetInternalFieldPointer"
"NanGetInternalFieldPointer/Nan::GetInternalFieldPointer"
"NanNewBufferHandle\\(([^;]+);/Nan::NewBuffer(\\1.ToLocalChecked();"
"(NanNew(<(v8::)?String>)?\\(\"[^\"]*\"\\))/\\1.ToLocalChecked()"