Skip to content

Instantly share code, notes, and snippets.

@ritwickdey
ritwickdey / README.md
Last active April 24, 2025 13:07
Mail Merge using gmail and google spreedsheet (PS: Most of the code is generated)
  1. It reads email template from gmail's draft, and reads email list from speadsheet.
  2. Write back to speedsheet after email sent (success or failed) and it's time
  3. support template variables.
  4. Smilar to google's mail merge app script but that doesn't work for more that 100 emails
  5. email, sent status & sent at are the required field in the spreedsheet, rest are the variables.

PS: Inline attachments are showing as normal attachments. (Bug)

@ritwickdey
ritwickdey / .env2envrc.mk
Last active March 20, 2023 15:03
Quickly convert .env (non exported variable) file to .envrc (exported variable)
# To convert .env file to .envrc
# usages: make [.env_file]2envrc
# e.g. "make .env2envrc" or "make .env.production2envrc"
%2envrc:
$(eval file := $*)
@(cat $(file) | sed 's/^/export /' > .envrc)
@echo ".envrc generated from $(file)"
# example
@ritwickdey
ritwickdey / go-webrtc-sample-example.go
Created February 20, 2022 09:59
go webrtc sample example
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/pion/webrtc/v3"
)
@ritwickdey
ritwickdey / infinite-loop-detection.js
Last active November 21, 2023 12:54
Infinite loop detection via AST transformation
export default function (babel) {
const { types: t } = babel;
const infiniteLoopDetector = babel.parse(`
function __infiniteLoopDetector() {
loopdetector.count += 1;
if(loopdetector.count > 10000) {
throw new Error("Infinte loop detected.")
//https://astexplorer.net/#/gist/6fa8fbfbc299ba7dcf27a83d50d89c26/3af7743eac480fd64e4b9013c9e0969097470959
export default function (babel) {
const { types: t } = babel;
return {
name: "ast-transform", // not required
visitor: {
ImportDeclaration(importPath) {
if (importPath.node.source.value !== "lodash") return;
/***
*
* @author Ritwick Dey (https://github.com/ritwickdey)
* @license MIT
*
* What is the hell?
* - This is a automated script to do n numbers of facebook comments.
*
* Perpose of the hell?
* You may seen such kind of post
@ritwickdey
ritwickdey / useLocalStorage.js
Created June 27, 2019 07:29
useLocalStorage React Hook
import { useState, useEffect } from 'react';
export const useLocalStorage = (storageKey, initialValue) => {
const [storageVal, setStorageVal] = useState(getFromLocalStorage(storageKey));
useEffect(() => {
setToLocalStorage(storageKey, storageVal);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [storageVal]);
@ritwickdey
ritwickdey / github-auto-close.js
Last active April 12, 2019 02:57
Auto Close Github issue by issue name (e.g. "Extension causes high cpu load" )
const comment = `Hello. few questions!!,
When you're getting this issue? after load of vscode or after clicking to Go Live ?
Is this happen every-time ? or random ?
Please reply here https://github.com/ritwickdey/vscode-live-server/issues/278
Duplicate of https://github.com/ritwickdey/vscode-live-server/issues/278
@ritwickdey
ritwickdey / MakeUnique.ts
Created January 11, 2019 09:34
MakeUnique
function makeUnique<T>(arr: T[], idSelector: (e: T) => string | number) {
const obj = {};
arr.forEach(e => {
obj[idSelector(e)] = e;
});
return Object.keys(obj).map(key => obj[key]) as T[];
}
@ritwickdey
ritwickdey / withCORS.js
Last active December 27, 2018 06:21
CORS Middleware (Higher Order Function) for firebase function // Just Nice Syntax
//For firebase funtion.
/*
Usage:
exports.foo = functions.https.onRequest(withCORS((req, res) => {
res.send("Hello World");
});
*/