Skip to content

Instantly share code, notes, and snippets.

View nakul5harma's full-sized avatar

Nakul sharma nakul5harma

  • Pune
View GitHub Profile
@nakul5harma
nakul5harma / genrate-otp.ts
Created March 20, 2022 14:42
Generate cryptographically secure OTP in TypeScript/ JavaScript/ NodeJS
import { randomBytes } from "crypto";
export const generateCryptographicallySecureOTP = (otpLength: number) => {
return parseInt(randomBytes(otpLength).toString("hex"), 16)
.toString()
.substr(0, otpLength);
};
@nakul5harma
nakul5harma / radial-distance.ts
Last active March 20, 2022 10:06
Radial distance between two locations using haversine formula
export interface Coordinates {
latitude: number;
longitude: number;
}
const getRadiansFromDegrees = (degrees: number) => {
return (degrees * Math.PI) / 180;
};
export const calculateRadialDistanceBetweenCoordinates = (