Skip to content

Instantly share code, notes, and snippets.

View mhsattarian's full-sized avatar
🎯
Focusing

Mohammad H. Sattarian mhsattarian

🎯
Focusing
View GitHub Profile
@mhsattarian
mhsattarian / applemoji.tsx
Created June 29, 2024 07:10
Apple Emoji React Component
/**
* Adopted from: https://gist.github.com/chibicode/fe195d792270910226c928b69a468206?permalink_comment_id=4568681#gistcomment-4568681
*/
import NextImage from 'next/image';
import { memo } from 'react';
function Applemoji({
emoji,
width = 72,
@mhsattarian
mhsattarian / next-routes.ts
Created May 14, 2024 09:01
Get All the valid routes for a Next.js application using the app router
/**
* Adopted from: https://github.com/Emiyaaaaa/next-routes-list/blob/8a91e25edcf7226b4534f11cfc04b39515162bf1/src/getNextRoutes.ts#L1
*/
import listPaths from 'list-paths';
export function getNextRoutes(
src = './app',
fileNames = ['page', 'route'],
extensions = ['tsx', 'ts', 'js', 'jsx', 'md', 'mdx']
@mhsattarian
mhsattarian / jotai-createJSONStorage.ts
Last active May 1, 2024 20:35
Jotai's createJSONStorage code with few tweaks to support custom subscribe functionality for persist storages
import { AsyncStorage, SyncStorage } from 'jotai/vanilla/utils/atomWithStorage';
type Unsubscribe = () => void;
type Subscribe<Value> = (
key: string,
callback: (value: Value) => void,
initialValue: Value
) => Unsubscribe;
@mhsattarian
mhsattarian / Radix-Carousel.tsx
Created February 25, 2024 20:49
A Radix Carousel component styled via PandaCSS
@mhsattarian
mhsattarian / nextjs_og_custom-font_rotue.tsx
Last active February 3, 2024 20:26
An example of using custom fonts with `next/og` and `nodejs` runtime:
/**
* adopted from: https://stackoverflow.com/a/77146678/5863267
*/
// directory structure for this code was:
// file: /app/(api)/thumb/ellipsis/route.tsx
// font file: /assets/fonts/<font>
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
@mhsattarian
mhsattarian / IGLive.content.js
Created January 17, 2024 18:01
A simple (browser)action Chrome extension to add a rotate Instagram lives/stories
function doSmthing() {
var videoEl = document.querySelector("video");
videoEl.setAttribute("controls", "");
var prevRotate = 0;
if (videoEl.style.transform)
prevRotate = parseInt(videoEl.style.transform.split("(")[1].slice(0, -4));
document.body.style.cssText = `
rotate: ${prevRotate + 90}deg;
@mhsattarian
mhsattarian / archillect-downlod-button.content.js
Created January 17, 2024 17:58
A simple contentScript Chrome extension to add a download button to Archillect images
const imgSrc = document.querySelector("#ii").src;
const soruces = document.querySelector("#sources");
const link = document.createElement("a");
link.textContent = "Download";
link.href = imgSrc.replace("66", "64");
link.download = "download";
link.target = "_blank";
@mhsattarian
mhsattarian / version.mjs
Last active July 25, 2022 15:13
Use current Jalali Date as NPM package version. run with zx.
#!/usr/bin/env zx
const branch = (await $`git branch --show-current`).stdout.trim();
if (branch === "debug") {
const currentVersion = (
await $`awk '/version/{gsub(/("|",)/,"",$2);print $2}' package.json`
).stdout.trim();
const date = new Date();
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mhsattarian
mhsattarian / video2webm.sh
Created February 3, 2022 13:36
Format video for telegram's video stickers (WEBM + VP9 + transparent layer + scale)
ffmpeg -i video.mp4 -c:v vp9 -pix_fmt yuva420p -b:v 1M -vf "fps=30,scale=512:-1" -an video.webm