Skip to content

Instantly share code, notes, and snippets.

View sayanriju's full-sized avatar

Sayan "Riju" Chakrabarti sayanriju

View GitHub Profile
@sayanriju
sayanriju / splitName.js
Created July 17, 2019 10:30
A simple function to split given Full Name into components First, Middle & Last
function splitName(full) {
const arr = full.split(" ").filter(c => c !== "")
const first = arr.shift()
const last = arr.pop()
const middle = arr.join(" ") || undefined
return { first, middle, last }
}
@sayanriju
sayanriju / index.ejs
Created May 14, 2019 05:55
Reset Password Form (for ejs)
<!DOCTYPE html>
<html lang=en>
<head>
<title>Reset Password</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Roboto:400,500italic' rel='stylesheet' type='text/css'>
<script src="http://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
@sayanriju
sayanriju / keypress.py
Created February 7, 2019 12:01
A tiny, nifty script for playing random musical notes on each keypress
#!/usr/bin/env python
## A tiny, nifty script for playing random musical notes on each keypress.
##
## Copyright Sayan "Riju" Chakrabarti <[email protected]> 2009-2019
## Released under WTFPL Version 2
## (DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE)
## Copy of license text can be found online at
## http://sam.zoy.org/wtfpl/COPYING
##
## External/System Dependencies:
@sayanriju
sayanriju / .htaccess
Created December 4, 2018 18:26
Redirect http to https for SPA
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
@sayanriju
sayanriju / daysSpentOnGitProject.sh
Last active June 9, 2018 10:57
Oneliner to count the total number of days spent on a git project
GIT_USER="${1-`git config user.name`}"
GIT_BRANCH=${2-master}
OFFSET=${3-0}
DAYS=`git log --pretty=format:"%cd %an" $GIT_BRANCH 2> /dev/null | grep -i "$GIT_USER" | awk '{print $1,$2,$3}' | uniq | wc -l`
echo "$GIT_USER spent `expr $DAYS - $OFFSET` days (tops!) on this git project ($GIT_BRANCH branch)"
/**
* Formats a number to a string in the lakh/crore (Indian) format.
* Also, add/truncate to two decimal places, as expected for a currency
* @param num The number to format
*/
function desiCurrency(num) {
let ret = num.toFixed(2)
ret = `${ret}` || ""
// works for integer and floating as well
let n1 = ret.split(".")
@sayanriju
sayanriju / Minimal_VirtualHost_Config.md
Last active March 17, 2023 13:24
Web Server Configs

Minimal VirtualHost Config

Nginx

server {
       listen 80;
       listen [::]:80;

       server_name example.com www.example.com;
@sayanriju
sayanriju / setup_node_mongo_digital_ocean.md
Last active July 8, 2020 11:36
Set up Digital Ocean Droplet for Node & MongoDB (optionally Redis)

Set up Digital Ocean Droplet for Node & MongoDB (optionally Redis)

Locale Setup

Append the following to the file /etc/environment:

LANG="en_US.UTF-8"  
LC_ALL="en_US.UTF-8"  
LANGUAGE="en_US.UTF-8" 
@sayanriju
sayanriju / fontconverter.py
Created August 24, 2017 17:18
Python Scripts to convert non-unicode Bangla fonts to Unicode
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# fontconverter.py
#
# Copyright 2014-17 Sayan "Riju" Chakrabarti <[email protected]>
#
# License: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@sayanriju
sayanriju / README.md
Last active July 2, 2022 19:07 — forked from RobK/serial.js
Generate Random Serial Keys

Synopsis

This is a simple package to generate (pseudo) random strings of specified length separated into "blocks" of specified blockLengths by specified separator characters. This makes this package suitable for generating license or product or serial keys.

The similar looking characters (and numbers) I, 1, 0 and O are always left out of the generated strings to avoid confusion.

Note that the generated keys are just random strings and there's no provision to check their validity cryptographically.

Installation

From npm registry: