Skip to content

Instantly share code, notes, and snippets.

☕️
One coffee every five minute.

Anam Ahmed theanam

☕️
One coffee every five minute.
Block or report user

Report or block theanam

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@theanam
theanam / otpverify.js
Last active Dec 24, 2019
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
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 / 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
@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 / 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 / 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"){
@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 / 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:
View dragdroptouch.js
var DragDropTouch;
(function (DragDropTouch_1) {
'use strict';
/**
* Object used to hold the data that is being dragged during drag and drop operations.
*
* It may hold one or more data items of different types. For more information about
* drag and drop operations and data transfer objects, see
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer">HTML Drag and Drop API</a>.
*
You can’t perform that action at this time.