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 / 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();
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
@mhsattarian
mhsattarian / tippy-textContent.js
Created January 16, 2022 07:25
Tippyjs plugin to use `textContent` of the child as content.
import type { Props, Plugin, LifecycleHooks } from 'tippy.js';
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface CustomProps {}
type FilteredProps = CustomProps &
Omit<Props, keyof CustomProps | keyof LifecycleHooks>;
type ExtendedProps = FilteredProps & LifecycleHooks<FilteredProps>;
@mhsattarian
mhsattarian / pg-wsl.md
Last active January 14, 2022 17:20
Postgres + WSL connection error

check which port postgres is working on:

# check the log
tail /var/log/postgresql/postgresql-14-main.log 

# or check the cluster list
pg_lsclusters
@mhsattarian
mhsattarian / node-git-blame.js
Created December 25, 2021 22:02
Get a file [git] contributors (blame) using node-git
const git = require('nodegit');
const pathToRepo = require("path").resolve("./.git");
const uniqBy = require('../../utils').uniqBy
let $repo = null;
/** Blame last file change | using commit id */
async function blameLast_old(filePath, callback) {
const repo = $repo ? $repo : await git.Repository.open(pathToRepo);
const blame = await git.Blame.file(repo, filePath.slice(2));