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 / content_script.js
Created April 29, 2024 16:06
Remove "Reels and short videos" from Facebook News Feed with less than 35 lines of JavaScript code. It works both on Desktop and Mobile web version of Facebook.
function removeReels(node) {
const bannedInnerTexts = ["Reels and short videos", "Reels"];
const text = node.querySelector(`div > span[dir="auto"]`)?.innerText ?? "";
const matchedOnDesktop = bannedInnerTexts.find((t) => t === text);
const matchedOnMobile = bannedInnerTexts.includes(
node.querySelector("div > span")?.innerText,
);
if (matchedOnDesktop) {
const child = node.querySelector("div");
@arafathusayn
arafathusayn / log.md
Created April 3, 2024 17:54
How I migrated my database from PlanetScale
@arafathusayn
arafathusayn / script.sh
Created October 4, 2023 12:09
Temp Fix for `bun install some-package@latest`
echo 'void async function() { const p = await Bun.file("package.json").json(); const out1 = Object.entries(p.dependencies).filter(([k,v]) => v === "latest").map(([k]) => k).reduce((acc, curr) => acc + " " +curr, "bun add"); const out2 = Object.entries(p.devDependencies).filter(([k,v]) => v === "latest").map(([k]) => k).reduce((acc, curr) => acc + " " +curr, "bun add -d"); console.log(`\n${out1}\n\n${out2}\n`) }()' > temp.js && bun run temp.js; rm temp.js
#!/usr/bin/env python3
import argparse
import glob
import os
import struct
import sys
from sentencepiece import SentencePieceProcessor
HPARAMS = keys = ["vocab_size", "dim", "multiple_of", "n_heads", "n_layers"]
@arafathusayn
arafathusayn / useEffect_alternative_example.tsx
Last active March 18, 2023 12:46
useEffect alternative for functional React components
import * as React from "react";
import { useState } from "react";
import withCleanup from "./withCleanup";
import withOnMount from "./withOnMount";
let loaded = false;
function Counter() {
const [count, setCount] = useState(0);
@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:

@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 / 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 / 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,
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: