Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View benjamingr's full-sized avatar
🖊️
Limited availability.

Benjamin Gruenbaum benjamingr

🖊️
Limited availability.
View GitHub Profile
function interceptNetworkRequests(ee) {
const open = XMLHttpRequest.prototype.open;
const send = XMLHttpRequest.prototype.send;
const isRegularXHR = open.toString().indexOf('native code') !== -1;
// don't hijack if already hijacked - this will mess up with frameworks like Angular with zones
// we work if we load first there which we can.
if (isRegularXHR) {
var input = `
O....#....
O.OO#....#
.....##...
OO.#O....O
.O.....O#.
O.#..O.#.#
..O..#O..O
.......O..
#....###..
@benjamingr
benjamingr / gist:0237932cee84712951a2
Last active October 6, 2023 08:31
Promise unhandled rejection tracking global handler hook

Possibly Unhandled Rejection NodeJS Promise Hook

###Unhandled Rejection Tracking

Several promise libraries such as bluebird and when as well as some native promise implementations offer potentially unhandled rejection tracking. This means that the following:

Promise.reject(new Error("err")); // never attach a `catch`
// About me:
// - Benji - Kid (Daniel), Dog (bimper), Wife (orit)
// - Excel Online client architecture @ Microsoft
// - Node.js project member - 7 years
// - A bunch of other open source stuff.
// - Magshimim since ±2014.
// - Taught startech (Nitzani Magshimim)
// - עקרונות מתקדמיים.
// - קורס פרוייקט for two years.
// - פיתוח תוכן / מנטור
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = &gpa.allocator();
var file = try std.fs.cwd().openFile("./sample.txt", .{});
const file_content = try file.readToEndAlloc(allocator.*, 1024 * 1024); // 1MB max read size
var iter = std.mem.split(u8, file_content, "\n");
defer allocator.free(file_content);
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = &gpa.allocator();
var file = try std.fs.cwd().openFile("./sample.txt", .{});
const file_content = try file.readToEndAlloc(allocator.*, 1024 * 1024); // 1MB max read size
var iter = std.mem.split(u8, file_content, "\n");
defer allocator.free(file_content);
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));
import { Readable, Transform, compose } from "stream";
{
// Before
const stream = new (class extends Readable {
constructor() {
super({ objectMode: true });
this.data = [1, 2, 3];
}
_read() {
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 {
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) {