Skip to content

Instantly share code, notes, and snippets.

Avatar
One coffee every five minute.

Anam Ahmed theanam

One coffee every five minute.
View GitHub Profile
@theanam
theanam / regex.txt
Created Sep 4, 2019
Regular Expression to match Bangladeshi Phone number
View regex.txt
/^(?:\+88|88)?(01[3-9]\d{8})$/
@theanam
theanam / number.js
Created Sep 29, 2018
LWHH JavaScript Course Number Project
View number.js
let x = parseInt(process.argv[2]);
let y = parseInt(process.argv[3]);
console.log(x+y);
@theanam
theanam / otpverify.js
Last active Oct 8, 2020
OTP verification without database, full sample source code
View otpverify.js
const otpGenerator = require("otp-generator");
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function createNewOTP(phone){
// Generate a 6 digit numeric OTP
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false});
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp
@theanam
theanam / checkRTC.js
Last active Jun 5, 2020
Check if user's network supports WebRTC transport by probing a webRTC data channel. Why? because despite having feature support in browser. It might fail because of network or a faulty/unsupported rtcConfig.
View checkRTC.js
/**
* Created By Anam Ahmed (https://anam.co)
* Test the browser's capability to establish RTCPeerConnection with supplied RTC Configuration
* How to use: probeRTC(RTCParam,false, callback) // will call callback function with true or false.
* If you don't supply the callback function it will return a Promise.
* The promise will resolve (with total time required for the whole round trip ,in ms) or reject (with error) based on the result.
* Setting verbose = true will print logs in console
* @param {RTCConfiguration} rtcConfig
* @param {Boolean} verbose
* @param {Function} callback [optional]
@theanam
theanam / docker-compose.yml
Created Aug 28, 2018
Docker Compose for Strapi with Mongodb
View docker-compose.yml
version : "3"
services:
strapi-mongo:
image: mongo
environment:
- MONGO_INITDB_DATABASE=strapi
volumes:
- ./db:/data/db
strapi-app:
@theanam
theanam / sendhash.js
Last active Oct 3, 2019
create SMS OTP hash
View sendhash.js
const otpGenerator = require("otp-generator");
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function createNewOTP(phone){
// Generate a 6 digit numeric OTP
const otp = otpGenerator.generate(6, {alphabets: false, upperCase: false, specialChars: false});
const ttl = 5 * 60 * 1000; //5 Minutes in miliseconds
const expires = Date.now() + ttl; //timestamp to 5 minutes in the future
const data = `${phone}.${otp}.${expires}`; // phone.otp.expiry_timestamp
View verifyhash.js
// These imports and values are the same from the create source code. Perhaps you should keep them in the same file
// For the sake of demonstration, the imports are used here as well.
const crypto = require("crypto");
const key = "verysecretkey"; // Key for cryptograpy. Keep it secret
function verifyOTP(phone,hash,otp){
// Seperate Hash value and expires from the hash returned from the user
let [hashValue,expires] = hash.split(".");
// Check if expiry time has passed
let now = Date.now();
@theanam
theanam / docker-compose.yml
Created Sep 22, 2019
Docker Compose for Simple WordPress
View docker-compose.yml
version: "3"
services:
# Wordpress
mysite:
image: wordpress:5.2.3-php7.1-apache
volumes:
- ./themes:/var/www/html/wp-content/themes
- ./plugins:/var/www/html/wp-content/plugins
ports:
@theanam
theanam / resize_image_in_frontend.js
Last active Jul 17, 2019
A small JavaScipt function to resize image in frontend and return a new JPEG file
View resize_image_in_frontend.js
/****
Creatd by Anam Ahmed (https://anam.co)
Sample Use:
document.querySelector("input[type=file]").addEventListener("change",function(e){
if(e.target.files.length){
_resample(e.target.files[0],1000,function(response){
console.log(response); // returns an object: {stats:<compression stats>,file:output file}
});
}
});
@theanam
theanam / logger.js
Created Apr 5, 2019
Stdout logs on Steroids
View logger.js
const moment = require('moment');
const colors = {
"green" :"\x1b[32m",
"yellow":"\x1b[33m%s\x1b[0m",
"red":"\x1b[31m",
"cyan":"\x1b[36m",
"blue":"\x1b[34m",
"default":""
}
module.exports = function (message,color="default"){
You can’t perform that action at this time.