This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input = ` | |
O....#.... | |
O.OO#....# | |
.....##... | |
OO.#O....O | |
.O.....O#. | |
O.#..O.#.# | |
..O..#O..O | |
.......O.. | |
#....###.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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. | |
// - פיתוח תוכן / מנטור |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Readable, Transform, compose } from "stream"; | |
{ | |
// Before | |
const stream = new (class extends Readable { | |
constructor() { | |
super({ objectMode: true }); | |
this.data = [1, 2, 3]; | |
} | |
_read() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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), | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 |
NewerOlder