Skip to content

Instantly share code, notes, and snippets.

View isurfer21's full-sized avatar

Abhishek Kumar isurfer21

View GitHub Profile
@isurfer21
isurfer21 / handlebars-cli.js
Last active August 12, 2023 18:50
A CLI app which compiles the template with handlebars, renders it with the data, and prints the output html to the console.
// Import the required modules
const fs = require('fs');
const path = require('path');
const handlebars = require('handlebars');
// Get the template and data file names from the command line arguments
const templateFile = process.argv[2];
const dataFile = process.argv[3];
// Check if the files exist and are valid
@isurfer21
isurfer21 / zipnsync.ps1
Created July 29, 2023 14:26
A PowerShell based CLI app to zip each folder in the source directory and paste them to the target directory.
$help = $false
if ($args -contains "-h" -or $args -contains "--help") {
$help = $true
}
if ($help) {
write-host "Usage"
write-host " zipnsync [options] <source> <target>"
write-host ""
write-host "Arguments"
@isurfer21
isurfer21 / cli-args-parser.rs
Last active July 26, 2023 08:20
Minimalistic embeddable CLI argument parser in rust without any dependencies.
use std::collections::HashMap;
use regex::Regex;
// Define a function that returns a tuple of a hashmap of flags and values and an array of non-flag arguments
fn parse_args() -> (HashMap<String, String>, Vec<String>) {
// Create a hashmap to store the flags and values
let mut flags = HashMap::new();
// Create an array to store the non-flag arguments
let mut args = Vec::new();
// Create regular expressions to match different kinds of flags
@isurfer21
isurfer21 / SnakeToCamelCaseConverter.js
Created July 11, 2023 15:56
The snake_case to camelCase converter CLI app
// Import the file system module
const fs = require('fs');
// Import the process module
const process = require('process');
// Define a function to convert snake_case to camelCase
function snakeToCamel(str) {
// Split the string by underscore
let words = str.split('_');
@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 / flame.js
Last active April 18, 2023 11:25
It is a legacy game of FLAME, that children and teenagers use to play on their crushes. The theory of flame states that it could forecast the relationship in between 2 person by doing a flame-test on their individual names.
/*
The Legacy Game of FLAME
Copyright (c) 2015 Nistush Tech Solution.
Protected by Creative Commons license (CC BY 4.0).
@file flame.js
@author Abhishek Kumar
*/
export function flame(argv) {
@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) {