Skip to content

Instantly share code, notes, and snippets.

View lap00zza's full-sized avatar

Jewel Mahanta lap00zza

View GitHub Profile
@lap00zza
lap00zza / run_node-gyp_windows.md
Last active October 31, 2018 16:13
Getting node-gyp to work on windows can be a bit of a hassle. This gist shows the exact steps.

Steps

  1. Download Visual Studio 2017 with "Desktop development with C++" workload and the default components selected.
  2. Add msbuild to PATH. For me its this directory: D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin.
  3. Install node-gyp globally: npm i -g node-gyp
  4. Python 2.7
    • Download python2.7
    • Install to C:\Python27
    • Rename python.exe to python2.exe
  • Add C:\Python27 to PATH
@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;