Skip to content

Instantly share code, notes, and snippets.

View arafathusayn's full-sized avatar
👨‍💻
Focusing

Arafat Husayn arafathusayn

👨‍💻
Focusing
View GitHub Profile
@arafathusayn
arafathusayn / redirect.ts
Last active July 11, 2022 16:10
Vercel Serverless Function for getting redirected URL from short-link services
import got from "got";
import { VercelRequest, VercelResponse } from "@vercel/node";
const redirect = async (request: VercelRequest, response: VercelResponse) => {
const url: string | undefined =
(request.query && request.query.url) || (request.body && request.body.url);
if (
(request.method === "GET" || request.method === "POST") &&
typeof url === "string" &&
@arafathusayn
arafathusayn / parse-xml.js
Created March 3, 2021 09:52
Postman Test Script - Parse XML API response & set environment variables from the parsed data
var parseString = require("xml2js").parseString;
var xml = pm.response.text();
parseString(xml, (err, data) => {
if (err) throw err;
// traverse and set env variable
pm.environment.set("ENV_NAME_HERE", data.whatever);
});
@arafathusayn
arafathusayn / removing_script.js
Last active July 8, 2025 17:19
Remove Tawk.to Branding (2022)
var removeBranding = function() {
try {
var element = document.querySelector("iframe[title*=chat]:nth-child(2)").contentDocument.querySelector(`a[class*=tawk-branding]`)
if (element) {
element.remove()
}
} catch (e) {}
}
const pipe = (...args: any[]) =>
args.reduce(
(prev, curr) => (typeof curr === "function" ? curr(prev) : curr),
args[0],
);
export default pipe;
@arafathusayn
arafathusayn / urls-to-stream.js
Created July 27, 2021 18:53
Get a single readable stream of contents from multiple URLs on Node.js
const { Readable } = require("stream");
const { default: got } = require("got");
/**
* @param {string[]} [urls]
* @param {import("got").Options} [options]
* @return {Promise<Readable>} `Promise<Readable>`
*/
const getStreamFromUrls = async (urls = [], options = {}) => {
async function* generateChunk() {
function rawFormDataToJSON(formDataStr) {
return JSON.stringify(formDataStr
.trim()
.split('\n')
.filter(l => !l.startsWith('//'))
.map(l => l.split(':'))
.reduce((a, c) => ({ ...a, [c[0]]: c[1] }), {}))
}
// USAGE:
@arafathusayn
arafathusayn / rate-limit.ts
Created June 14, 2022 10:20
TypeScript Next.js Serverless Function API Rate-Limit using LRU Cache
import { NextApiResponse } from "next";
import LRU from "lru-cache";
const rateLimit = (options: {
uniqueTokenPerInterval: number;
interval: number;
}) => {
const tokenCache = new LRU<string, number[]>({
max: options.uniqueTokenPerInterval || 500,
maxAge: options.interval || 60000,
@arafathusayn
arafathusayn / index.ts
Created September 18, 2022 10:16
Amount in Words (Lakh-Crore system) in TypeScript
const a = [
"",
"one ",
"two ",
"three ",
"four ",
"five ",
"six ",
"seven ",
"eight ",
@arafathusayn
arafathusayn / Code.gs
Created November 20, 2022 13:28
Get an email when your lock starts to unlock using Google Apps Script
const lockId = "PASTE_YOUR_LOCK_ID_HERE";
function checkIfEmailSentAlready() {
const sheetId = "PASTE_YOUR_SPREADSHEET_ID_HERE";
const sheet = SpreadsheetApp.openById(sheetId);
const columns = sheet
.getRange("A1:B1000")
.getValues()
@arafathusayn
arafathusayn / expo-typescript-eslint-prettier.md
Last active March 6, 2023 10:42 — forked from yovany-lg/expo-typescript-eslint-prettier.md
Setting up React Navite: Expo + Typescript + Eslint (Airbnb) + Prettier

Steps to get started with Expo, Typescript, ESLint and Prettier

The first step is to use the Expo CLI to initialize the project. If you don't have the latest version of the Expo CLI tool, (or you don't have it installed) run npm install -g expo-cli.

Now run the following commands in the same order:

  • expo init my-app -t expo-template-blank-typescript
  • npx install-peerdeps --dev eslint-config-airbnb
  • npm i --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
  • npm i --save-dev prettier eslint-config-prettier eslint-plugin-prettier

Create or edit the file .eslintrc.json with the following content: