Skip to content

Instantly share code, notes, and snippets.

View sayanriju's full-sized avatar

Sayan "Riju" Chakrabarti sayanriju

View GitHub Profile
@sayanriju
sayanriju / pipeline.js
Last active September 25, 2024 04:57
Multigraph Pipeline implementation using events
const EventEmitter = require('events');
/**
* Pipeline class to manage a sequence of functions using an event-driven approach.
*/
class Pipeline {
name; // Name of the pipeline
#initialData = {}; // Initial data
#connRunSeq = []; // Connection run sequence
#ee; // EventEmitter instance
local ret_status="%(?:%{$fg_bold[green]%}»:%{$fg_bold[red]%}»%s)"
PROMPT='🔥%{$fg_bold[cyan]%}%p %{$fg[cyan]%}%c ${ret_status} %{$fg[green]%}%{$reset_color%}'
RPROMPT='$(git_prompt_info)%{$fg_bold[white]%}%{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[yellow]%} "
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg_bold[yellow]%}%{$fg[red]%} 🗴 %{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[yellow]%}%{$fg[green]%} 🗹 %{$reset_color%}"
function *primeGenerator() {
let knownPrimes = [2]
const isPrime = (num) => knownPrimes.find(p => num % p === 0) === undefined
let n = 2
while (true) {
if (isPrime(n)) {
knownPrimes.push(n)
yield n
}
n++
@sayanriju
sayanriju / index.html
Last active January 28, 2021 09:25
Service Worker for Caching Images using IndexedDB
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>Service worker demo</title>
<!--[if lt IE 9]>
@sayanriju
sayanriju / Vagrantfile
Last active December 18, 2020 12:42
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
$script = <<-SCRIPT
rsync -a --delete --delete-excluded --exclude 'node_modules' /vagrant/ /home/vagrant/project
cd /home/vagrant/project
npm install --unsafe-perm
pm2 kill && pm2 start bin/www
SCRIPT
Vagrant.configure("2") do |config|
@sayanriju
sayanriju / .eslintrc
Last active June 18, 2020 13:22
Generate Postman Collection scaffolds from Apidoc documentation
{
"env": {
"es6": true,
"node": true,
"mocha": true
},
"extends": "airbnb-base",
"rules": {
"func-names": [
"error",
@sayanriju
sayanriju / kaperkar.js
Last active April 23, 2020 08:19
Calculate Kaprekar's Constant
function isSame(str1, str2) {
return String(str1).split('').sort().join('') === String(str2).split('').sort().join('')
}
function kaprekar(num, seed = num, iterations = 0) {
const digits = String(num).padStart(String(seed).length, '0').split('')
const big = Number(digits.sort().reverse().join(''))
const small = Number(digits.sort().join(''))
const diff = big - small
if (isSame(num, diff)) return console.log(seed, iterations, diff)
kaprekar(diff, seed, iterations + 1)
@sayanriju
sayanriju / etc-nginx-sites-available.conf
Created November 25, 2019 11:50
NGINX Virtual Host Config with http->https redirection (Certbot)
server {
server_name example.com;
root /home/ls/app/;
index index.html;
location / {
try_files $uri $uri/ =404;
# try_files $uri /index.html =404;
}
@sayanriju
sayanriju / conway.js
Created November 24, 2019 07:15
Conway Sequence
function lookandsay(str) {
return str.replace(/(.)\1*/g, (seq, p1) => seq.length.toString() + p1)
}
function conway(n) {
if (n === 1) return "1"
return lookandsay(conway(n - 1))
}
@sayanriju
sayanriju / sleep.js
Created October 9, 2019 10:36
Async Sleep Function
async function sleep(secs = 1) {
return new Promise(r => setTimeout(() => r(), secs * 1000))
}