Skip to content

Instantly share code, notes, and snippets.

View rakibulhaq's full-sized avatar
🏠
Working from home

rakibulhaq rakibulhaq

🏠
Working from home
View GitHub Profile
@theanam
theanam / otpverify.js
Last active March 31, 2024 17:05
OTP verification without database, full sample source code
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
@abmmhasan
abmmhasan / PostgreSQL Queries and Commands: Export_Import.sql
Last active January 9, 2024 04:12
Useful PostgreSQL Queries and Commands
-- Import(FROM) / Export(TO) CSV file from/into a table
-- Ref: https://www.postgresql.org/docs/current/sql-copy.html
-- If processing all columns, no need column specification
-- If CSV file don't include header, remove 'HEADER' from below query
-- For Export, can also specify Query, instead of Table & Column name
COPY table_name (column_1, column_2, column_3, column_5)
[FROM/TO] 'csv_file_location' DELIMITER ',' CSV HEADER QUOTE '"' ESCAPE '"'
-- Dump database on remote host to file
-- Ref: https://www.postgresql.org/docs/current/app-pgdump.html
@sdgluck
sdgluck / query.js
Last active April 23, 2024 17:48
Pagination using Mongo: populate, match, sort, count, and limit with the aggregation pipeline
/**
* Query blog posts by user -> paginated results and a total count.
* @param userId {ObjectId} ID of user to retrieve blog posts for
* @param startRow {Number} First row to return in results
* @param endRow {Number} Last row to return in results
* @param [filter] {Object} Optional extra matching query object
* @param [sort] {Object} Optional sort query object
* @returns {Object} Object -> `{ rows, count }`
*/
function queryBlogPostsByUser (userId, startRow, endRow, filter = {}, sort = false) {