Skip to content

Instantly share code, notes, and snippets.

View bishil06's full-sized avatar
🏠
Working from home

bishil06 bishil06

🏠
Working from home
View GitHub Profile
@bishil06
bishil06 / _NodeJS_read_directory.md
Last active January 11, 2021 10:22
Node.JS read directory

read directory - opendir vs readdir

create 1000 txt file.
calc 10 times runtime.

@bishil06
bishil06 / _readdir_async_vs_Promise.all.md
Created January 25, 2021 11:14
async await readdir vs Promise.all readdir

read directory - async await vs Promise.all

create 1000 txt file to sampleDir directory. calc 1000 times readdir.

async await bottleneck

@bishil06
bishil06 / createMD5.js
Created February 5, 2021 13:22
Node.JS create md5 hash from file
const crypto = require('crypto');
function createMD5(filePath) {
return new Promise((res, rej) => {
const hash = crypto.createHash('md5');
const rStream = fs.createReadStream(filePath);
rStream.on('data', (data) => {
hash.update(data);
});
@bishil06
bishil06 / _NodeJS_stack_caculator.md
Created February 6, 2021 06:37
Node.JS stack calculator
@bishil06
bishil06 / zip.js
Created February 9, 2021 02:12
_JavaScript_zip_iterable
function *zip(iter1, iter2) {
const a = iter1[Symbol.iterator]();
const b = iter2[Symbol.iterator]();
let va = null;
let vb = null;
while (!((va = a.next()).done) && !((vb = b.next()).done)) {
yield [va.value, vb.value];
}
}
@bishil06
bishil06 / enumerate.js
Created February 9, 2021 02:16
_JavaScript_enumerate_iterable
function *enumerate(init=0, iter) {
if (init[Symbol.iterator]) {
iter = init[Symbol.iterator]();
init = 0;
}
let count = init;
for(const a of iter) {
yield [count, a];
count += 1;
@bishil06
bishil06 / range.js
Created February 9, 2021 02:21
_JavaScript_range_iterable
function *range(start=0, stop, step=1) {
while(start < stop) {
yield start;
start+=step;
}
}
console.log(...range(0, 5)); // 0 1 2 3 4
console.log(...range(0, 10, 2)); // 0 2 4 6 8
console.log(...range(1, 20, 3)); // 1 4 7 10 13 16 19
@bishil06
bishil06 / stack.js
Created February 9, 2021 04:22
_JavaScript_stack
class Stack{
constructor() {
this.list = [];
this.top = null;
}
push(v) {
this.list.push(v);
this.top = v;
}
@bishil06
bishil06 / queue.js
Created February 9, 2021 04:31
_JavaScript_queue
class Queue {
constructor() {
this.list = [];
this.first = null;
}
enqueue(v) {
if (this.first === null) {
this.first = v;
}
@bishil06
bishil06 / _NodeJS_Reverse_Array.md
Created February 18, 2021 21:39
_JavaScript_Reverse_Array

JS Reverse Array

let arr1 = Array.from({length: 10000000}, (_, i) => i);

Node version 15.8

  • reverse method 274ms