Skip to content

Instantly share code, notes, and snippets.

@hellivan
hellivan / diff_dir.sh
Last active November 14, 2022 07:13
Script that finds differences between 2 directories using find and md5sum
#!/bin/bash
DIR_1="$1"
DIR_2="$2"
echo "Comparing directories ${DIR_1} <-> ${DIR_2}"
OLD_IFS=$IFS
for FILE_1 in `find ${DIR_1} -type f -printf '%P\n'`
do
@hellivan
hellivan / electron-async-error-test.js
Created March 6, 2020 08:36
Electron 8 / v8 async functions UnhandledPromiseRejectionWarning Problem
console.log(process.versions);
async function foo(msg) {
throw new Error(msg);
}
async function bar(msg) {
return foo(msg);
}
@hellivan
hellivan / rxjs-ts_type_inference_error.ts
Created December 11, 2019 15:38
Code snippet for reproducing a type inference error with rxjs and typescript
import {Observable, of as observableOf} from 'rxjs';
import {switchMap} from 'rxjs/operators';
// THIS ONLY FAILS IN STRICT MODE
const foo: Observable<string | null> = observableOf('test').pipe(
switchMap(f => {
if(f) {
return observableOf([]);
}
return observableOf(null);
@hellivan
hellivan / nod-opcua-timer-leak.js
Last active November 5, 2019 14:20
Script that demonstrates a setInterval timer leak in the node-opcua library, caused by incomplete cleanup of PeriodicClockAdjustmement on connection failure
let setIntervalCalls = 0;
const realSetInterval = global.setInterval;
global.setInterval = (...args) => {
setIntervalCalls++;
return realSetInterval(...args);
}
let clearIntervalCalls = 0;
const realClearInterval = global.clearInterval;
global.clearInterval = (...args) => {
clearIntervalCalls++;
@hellivan
hellivan / mongoose_includes_error.js
Created September 27, 2019 11:21
Gist for reproducing an error in mongoose CoreMongooseArray.includes function
const mongoose = require('mongoose');
const personSchema = new mongoose.Schema({
name: String,
friends: [{
name: String
}]
});
const Person = mongoose.model('Person', personSchema);
// Global structure required by validate function
const validate = {
errors: null
};
// Global formats required by validate function
const formats = {
date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s](?:[0-2]\d:[0-5]\d:[0-5]\d|23:59:60)(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i
};