Skip to content

Instantly share code, notes, and snippets.

Avatar
🖊️
🍍🍎🖊️

Benjamin Gruenbaum benjamingr

🖊️
🍍🍎🖊️
View GitHub Profile
View parse-json-stream-modern.mjs
import { default as parser } from 'stream-json';
import { Readable } from 'stream';
const parkingViolations = await fetch('https://s3.amazonaws.com/philadelphia-parking-violations-raw-data/parking_violations_2017.json');
await Readable.fromWeb(parkingViolations.body)
.pipe(parser())
.filter(violation => violation.name === 'stringChunk')
.map(x => x.value)
.take(5)
.forEach(v => console.log(v));
View security-guild-meetup-exercise-port-scanner.mjs
import { connect } from 'net';
import { once } from 'events';
import { Readable } from 'stream';
function* range(from, to) {
for(let i = from; i < to; i++) yield i;
}
async function tryToConnectToPort(port, host) {
const socket = connect(port, host);
try {
View stream-evolution.mjs
import { Readable, Transform, compose } from "stream";
{
// Before
const stream = new (class extends Readable {
constructor() {
super({ objectMode: true });
this.data = [1, 2, 3];
}
_read() {
View async-iterator-cancellation.js
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
async function* delayedRange() {
try {
for(let i = 1; i <= 1000; i++) {
await delay(100);
yield i;
}
} catch (e) {
View mongo.js
// Let's say I have transaction code that looks like:
let state = 1;
session.withTransaction(async () => {
// this can retry, which means otherFn can run twice and possible insert the wrong value or in the wrong order
state++;
await Promise.all([
coll1.insertOne({ abc: 1 }, { session });
otherFn(state, session),
])
View chan.js
/*
Makes a channel that buffers up to n items
*/
function chan(n) {
const data = []; // data not yet read
const readersBacklog = []; // readers waiting for data
const writersBacklog = []; // writers waiting for data
let disposed = false;
// TODO(Benjamin) - disposing
View index.js
'use strict';
const { withToken, token } = require('./token.js');
const { setTimeout } = require('timers/promises');
const controller = withToken(() => {
flow();
});
setTimeout(100).then(() => {
console.log('aborting');
View advent-5-input.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
FFBBBFBLRL
BFFFBFBRRR
BFFFBFBLRL
BFFBFBBLRR
BBFFBFFRLL
BFFFBFBRLR
FFFFBBBRLR
BBFFFBBRRR
BBFBFBBRRR
BFFBBBFLRR
View horrible-hack.js
'use strict';
require('v8').setFlagsFromString('--allow-natives-syntax');
// Extracted from v8/src/runtime/runtime.h
const methodNames = [
"Abort",
"AbortJS",
"AbortCSAAssert",
"ArraySpeciesProtector",
View testimio.md

Testim.io

Who am I

Hi, I'm Benji, I'm a developer @ Testim.io for the last year and a half. I was asked to write a little about how we work here at Testim.io. Other than that this is me on GitHub and Stack Overflow.

Developer Point of View.

Testim is an E2E functional test recording and playback tool. We automate the hard parts of end to end testing which are stability and fast authoring. In addition we provide a lot of useful root-cause analysis information for your tests.