Skip to content

Instantly share code, notes, and snippets.

View isurfer21's full-sized avatar

Abhishek Kumar isurfer21

View GitHub Profile
@isurfer21
isurfer21 / goclean
Created September 20, 2019 05:05
Golang package cleaner
#!/usr/bin/env sh
goclean() {
local pkg=$1; shift || return 1
local ost
local cnt
local scr
echo "Clean removes object files from package source directories (ignore error)"
go clean -i $pkg
@isurfer21
isurfer21 / logout
Created September 20, 2019 05:16
Logout from macOS via Terminal command
#!/usr/bin/env sh
sudo pkill loginwindow
@isurfer21
isurfer21 / tomcat
Last active December 11, 2019 02:22
Shell based Apache Tomcat agent
#!/usr/bin/env sh
APP_VER="19.9.20"
version() {
echo " Version $APP_VER \n"
}
help() {
echo "\n Apache Tomcat Agent version $APP_VER \n Copyright (c) 2019 Abhishek Kumar. All rights reserved."
echo "\n Options:"
@isurfer21
isurfer21 / vitaarak.js
Last active December 11, 2019 02:26
Vitaarak is a zero dependency node.js based mime-type supported simple HTTP server with CLI and made for quick integration in any dev project.
const http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs");
const mimeTypes = {
html: "text/html",
jpeg: "image/jpeg",
jpg: "image/jpeg",
png: "image/png",
@isurfer21
isurfer21 / duration.js
Created February 11, 2020 07:41
Calculates the exact duration in between 2 given dates.
/*
DURATION
Calculates the exact duration in between 2 given dates.
Copyright (c) 2020 Abhishek Kumar.
Protected by Creative Commons license (CC BY 4.0).
@file duration.js
@author Abhishek Kumar
*/
@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
*/
@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 / 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, '""');