Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View theanam's full-sized avatar
One coffee every five minute.

Anam Ahmed theanam

One coffee every five minute.
View GitHub Profile
@theanam
theanam / keybase.md
Created July 7, 2014 06:16
Keybase account proof

Keybase proof

I hereby claim:

  • I am theanam on github.
  • I am theanam (https://keybase.io/theanam) on keybase.
  • I have a public key whose fingerprint is 9F55 C1A3 C36F F2F0 A2B9 46B8 0514 642C B259 A081

To claim this, I am signing this object:

@theanam
theanam / gcd.js
Created September 29, 2015 09:38
Euclid's algorithm for finding GCD
function gcd(a,b){
if(a==0 || b==0){
return a;
}
else{
return gcd(b,a%b);
}
}
//test
console.log(gcd(10,45));
@theanam
theanam / Sieve.js
Last active September 29, 2015 09:39
Sieve of Eratosthenes in JavaScript
/*
Sample Implementation of Sieve algorithm for 1-3000
not optimized yet
*/
var ar = [];
var max = 3000;
//loop should run only till the square root of the maximum
var maxloop = Math.round(Math.sqrt(max));
for(a=0;a<max;a++){
ar.push(true);
@theanam
theanam / quicksort.js
Last active September 29, 2015 09:40
Quick Sort algorithm in JavaScript (with a relatively bigger memory complexity, for demonstration purpose only)
var unsorted = [53,12,22,87,74,67,23,45,77,1,8,44];
function quickSort(arr){
if(arr.length<2)
return arr;
var smaller = [];
var larger = [];
var pivot = arr[Math.floor(Math.random()*arr.length)];
for(i=0;i<arr.length;i++){
if(arr[i]<=pivot)
smaller.push(arr[i])
@theanam
theanam / logger.js
Created April 5, 2019 17:53
Stdout logs on Steroids
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 / docker-compose.yml
Created September 22, 2019 13:11
Docker Compose for Simple WordPress
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 / verifyhash.js
Last active October 3, 2019 05:27
Verify hash
// 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 August 28, 2018 08:49
Docker Compose for Strapi with Mongodb
version : "3"
services:
strapi-mongo:
image: mongo
environment:
- MONGO_INITDB_DATABASE=strapi
volumes:
- ./db:/data/db
strapi-app:
@theanam
theanam / checkRTC.js
Last active June 5, 2020 19:14
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.
/**
* 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]
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>.
*