Skip to content

Instantly share code, notes, and snippets.

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

Jewel Mahanta lap00zza

🏠
Working from home
View GitHub Profile
@lap00zza
lap00zza / shiftArray.js
Last active November 10, 2018 13:36
Shift an array to left or right
// +by shift left
// -by shift right
const shiftArray = (arr, by) => {
const _by = (by | 0) % arr.length;
const rest = by > 0 ? arr.slice(0, _by) : arr.slice(_by);
return arr.map(
(_, i) => arr[i + _by] !== undefined
? arr[i + _by]
: rest.shift()
);
@lap00zza
lap00zza / evalNode.js
Created November 13, 2018 19:06
Evaluate JS code in a node child process
const { spawn } = require("child_process");
const { Readable, Duplex, Writable } = require("stream");
const wrapRS = txt => {
const r = new Readable();
r._read = () => {
r.push(txt);
r.push(null);
};
return r;
@lap00zza
lap00zza / nanoWs-client.js
Last active November 12, 2021 09:59
A barebones WebSocket client for nodejs
/**
* nanoWS
* A very basic websocket client. Its does not fully cover rfc6455 so
* it must not used for any real world work. I wrote it to find out
* how websockets actually worked.
*
* @licence MIT
* @author Jewel Mahanta <jewelmahanta@gmail.com>
*/