Skip to content

Instantly share code, notes, and snippets.

@gitSambhal
gitSambhal / index.js
Last active April 14, 2024 06:03
# Compare and find missing contacts This script compares two VCF contact files, extracts the phone numbers, finds missing numbers between the two files, and filters the original contacts to only those that contain missing numbers. To run: - Install dependencies npm install - Run script node index.js - Output files written to /out folder - missin…
const fs = require('fs');
const vcf = require('vcf');
const vcardParser = require('vcard-parser');
// Utils
const writeToFile = (fileName, content) => {
fs.writeFileSync(fileName, content);
};
const cleanPhoneNumber = (num) => {
@gitSambhal
gitSambhal / ssl-certificate-generation-in-ubuntu.txt
Created February 23, 2024 14:08
Generate SSL certificate using Certbot in Ubuntu
=========================================
Step 1 — Installing Certbot
sudo snap install core; sudo snap refresh core
Remove if ready installed
sudo apt remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
@gitSambhal
gitSambhal / vscode-typescript-node-debug-launch.json
Last active December 15, 2023 04:18
Debug Typescript Nodejs App in Vscode using ts-node
{
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug - App",
"runtimeArgs": ["-r", "ts-node/register"],
"args": ["${workspaceFolder}/src/index.ts"]
}
]
@gitSambhal
gitSambhal / deasyncify.js
Created December 10, 2023 08:48
Nodejs Tutorial - Convert Async functions into Sync functions
const deasync = require('deasync')
const axios = require('axios')
const cp = require('child_process');
function promiseToSync(func) {
let isDone = false;
let resp
func().then(data => {
isDone = true;
resp = data
@gitSambhal
gitSambhal / multi-language-regext-test.js
Last active November 14, 2023 06:57
Test regex on multiple languages in Javascript
// https://gist.github.com/gitSambhal
// Author: Suhail Akhtar
const regex = /^[\p{L}\p{M}\p{N}\p{P}\p{S}\s]+$/u;
const names = [
// English
[
'John',
'Mary',
@gitSambhal
gitSambhal / functions.bat
Created September 11, 2023 08:38
Batch file with functions
@echo off
echo PROGRAM_NAME:%~nx0 Start
echo.
================================
SET debugMode=%1
call :myFunc1 %debugMode%
call :myFunc2 para1 "para2 hello"
================================
@gitSambhal
gitSambhal / gist:af93683dfaec527824e43337dcfbeee3
Created November 30, 2021 12:47
HTML table from array of objects in Javascript
/**
*
*
* @param {Array} arr Array of object to convert to HTML table
* @param {Array} takeOnly Array of keys to keep in the resulting HTML table
* @param {Array} blacklist Array of keys to skip in the resulting HTML table
* @return {String} HTML Table
*/
export const ArrayOfObjectsToTable = function ({ arr = [], takeOnly = [], blacklist = [] }) {
@gitSambhal
gitSambhal / Invalid Host Header NGROK
Created May 14, 2020 06:49 — forked from xola139/Invalid Host Header NGROK
When Invalid Host Header when ngrok tries to connect to Angular or React dev server
When Invalid Host Header when ngrok tries to connect to Angular or React dev server use this form for run ngrok.
ngrok http 8080 -host-header="localhost:8080"
ngrok http --host-header=rewrite 8080
@gitSambhal
gitSambhal / slugify.js
Created February 10, 2020 10:43 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
function saveSelection() {
if (window.getSelection) {
var sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
return sel.getRangeAt(0);
}
} else if (document.selection && document.selection.createRange) {
return document.selection.createRange();
}
return null;