Skip to content

Instantly share code, notes, and snippets.

View isurfer21's full-sized avatar

Abhishek Kumar isurfer21

View GitHub Profile
@isurfer21
isurfer21 / wasi.cmd
Created July 1, 2023 18:05
Download the latest wasi-sdk from https://github.com/WebAssembly/wasi-sdk/releases, extract it somewhere, create environment variable with WASI_SDK_PATH name and store the path of extracted wasi-sdk. Copy the wasi.cmd & wasi.ps1 files from given gist and paste it somewhere globally accessible. Now you can can access the wasi-sdk's executables vi…
@echo off
setlocal
set wasi_bin_path=%WASI_SDK_PATH%\bin
set wasi_self=%~n0
set wasi_cmd=%1
if "%wasi_cmd%" == "" (
echo Usage: %wasi_self% executable [arguments]
exit /b 1
)
if not exist "%wasi_bin_path%\%wasi_cmd%.exe" (
@isurfer21
isurfer21 / comment-remover.js
Created June 22, 2023 18:18
It can remove the single and multiline comments from any JavaScript or node.js files
const fs = require("fs").promises;
const path = require("path");
// A class to remove all comments from a js file
class CommentRemover {
// A constructor that takes a file name as an argument
constructor(filePath) {
// A property to store the file name
this.filePath = filePath;
// A property to store the file content
@isurfer21
isurfer21 / static-server.js
Last active June 22, 2023 15:15
Sample minimal static server
/*
@title Sample minimal static server
@file static-server.js
@setup npm install connect serve-static
@usage node static-server.js
*/
const os = require('os');
const path = require('path');
const connect = require('connect');
const serveStatic = require('serve-static');
@isurfer21
isurfer21 / ConvertArrayToCSV.js
Created April 18, 2023 11:21
This function takes an array of arrays as input and returns a CSV string. The first element of the input array is assumed to be the header row.
function convertArrayToCSV(arr) {
const arrayCopy = [...arr];
const header = arrayCopy.shift();
const csv = [
header.join(','),
...arrayCopy.map((row) => row.join(',')),
].join('\n');
return csv;
}
@isurfer21
isurfer21 / ConvertArrayOfObjectsToCSV.js
Created April 18, 2023 11:17
This function takes an array of objects as input and returns a CSV string. The keys of the first object in the input array are assumed to be the header row. If any object in the array has extra properties than others, the CSV will adjust accordingly. The updated function checks each cell value for commas, quotes, or newlines and wraps it in doub…
function convertArrayOfObjectsToCSV(data) {
const arrayCopy = [...data];
const header = Object.keys(arrayCopy[0]);
const csv = [
header.join(','),
...arrayCopy.map((row) => {
return header.map((fieldName) => {
let cellValue = row[fieldName] !== undefined ? row[fieldName] : '';
if (typeof cellValue === 'string') {
cellValue = cellValue.replace(/"/g, '""');
@isurfer21
isurfer21 / cli-arg-parser.js
Created July 28, 2022 17:05
Minimalistic embeddable argument parser in node.js without any dependencies
#!/usr/bin/env node
const APP_NAME = 'CliApp';
const APP_VER = '1.0.0';
class CliArgParser {
constructor() {
this.argv = process.argv.slice(2);
this.args = this.map();
}
@isurfer21
isurfer21 / tabulator.js
Created October 31, 2021 17:21
Tabulate the array of objects to render as HTML table
class Tabulator {
constructor(container) {
this.container = $(container);
}
setColumnHeader(columns) {
this.columns = columns;
}
toTable(data) {
@isurfer21
isurfer21 / app-cli.js
Created June 27, 2021 03:24
Simplest CLI based node.js app with in-built argument parser without any dependencies
const flags = { _: [] };
process.argv.forEach((s, e) => {
if (e >= 2)
if (/^[\-\-]{1,2}.+[\=\:].*$/.test(s)) {
let e = s.split(/[\=\:]/),
l = e[0].lastIndexOf("-");
l < 2 && (flags[e[0].substring(l + 1)] = e[1]);
} else if (/^[\-\-]{1,2}.+$/.test(s)) {
let e = s.lastIndexOf("-");
e < 2 && (flags[s.substring(e + 1)] = !0);
@isurfer21
isurfer21 / GFKeyFetcher.js
Last active February 18, 2020 11:39
GFKeyFetcher is a node.js based CLI tool to fetch input field label & name as key-value pair from Google Form
/*
GFKeyFetcher
Google Form Key Fetcher
Copyright (c) 2014 Nistush Tech Solution.
Protected by Creative Commons license (CC BY 4.0).
@file GFKeyFetcher.js
@author Abhishek Kumar
*/
@isurfer21
isurfer21 / wspm.js
Last active February 18, 2020 16:47
Web Shell Package Manager
/*
WSPM
Web Shell Package Manager
Copyright (c) 2020 Abhishek Kumar.
Protected by Creative Commons license (CC BY 4.0).
@file wspm.js
@author Abhishek Kumar
*/