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 / 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 / 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 / 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 / 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>
*/
@lap00zza
lap00zza / idgen.js
Last active October 6, 2018 17:52
Quick 'n' dirty id generator
const generateId = (len=16) => {
const allowedRanges = [[48, 57], [65,90], [97, 122]];
let str = "";
let expand = allowedRanges.reduce((acc, each) => {
let [start, end] = each;
let nums = [];
for(let i = start; i <= end; i++) {
nums.push(i);
};
return acc.concat(nums);
@lap00zza
lap00zza / urlify_headings.js
Created October 4, 2018 14:19
Most websites don't add anchors to headings. Its important because you can bookmark it at that spot instead of scrolling all the way down. This bookmarklet helps solve that.
javascript:(document.querySelectorAll("h1[id],h2[id],h3[id],h4[id],h5[id],h6[id]").forEach(x => x.innerHTML = `<a href="#${x.id}">${x.innerHTML}</a>`))
@lap00zza
lap00zza / start_zsh.bat
Created October 2, 2018 07:59
Setting up msys2 zsh on Webstorm can be a bit of a hassle. This script helps out with that. Download it and point terminal to it.
@echo off
set MSYSTEM=MSYS
set MSYS2_PATH_TYPE=inherit
set SHELL=/usr/bin/zsh
set MSYS=winsymlinks:nativestrict
"D:\msys64\usr\bin\zsh.exe" -i --login
@lap00zza
lap00zza / static-server.js
Created September 26, 2018 20:21
Easily serve all your static files
const http = require("http");
const fs = require("fs");
const path = require("path");
const util = require("util");
const PORT = process.argv[2] || 8080;
const __cwd = process.cwd();
const _access = util.promisify(fs.access);
const _readdir = util.promisify(fs.readdir);
@lap00zza
lap00zza / defender_scan.sh
Created September 5, 2018 18:56
A simple shell wrapper for Windows Defender (tested with msys2/mintty)
#!/bin/sh
# A simple shell wrapper for Windows Defender
defender_path="/c/Program Files/Windows Defender/MpCmdRun.exe"
if [ $1 == "--help" ]
then
echo "Usage:"
echo " ./defender_scan /full/path/to/file_or_directory"
echo "Note:"

Keybase proof

I hereby claim:

  • I am lap00zza on github.
  • I am lapoozza (https://keybase.io/lapoozza) on keybase.
  • I have a public key whose fingerprint is 2CFE 64FF D63F CEEE 3EA4 DD1B ACBB 0D63 AD9D 3A7E

To claim this, I am signing this object: