Skip to content

Instantly share code, notes, and snippets.

View realamirhe's full-sized avatar
♾️

Amir.H Ebrahimi realamirhe

♾️
View GitHub Profile
@realamirhe
realamirhe / next.config.ts
Created December 10, 2025 11:27
Add file logging to next.js loader based on tanstack devtool console enhancer
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
turbopack: {
rules: {
"*.{ts,tsx}": {
loaders: ["./sample-console-log.mjs"],
},
},
},
@realamirhe
realamirhe / convertor.js
Last active August 3, 2025 07:29
convert number digits from {english, persian, arabic} to {english, persian, arabic}
const e2p = s => s.replace(/\d/g, d => '۰۱۲۳۴۵۶۷۸۹'[d])
const e2a = s => s.replace(/\d/g, d => '٠١٢٣٤٥٦٧٨٩'[d])
const p2e = s => s.replace(/[۰-۹]/g, d => '۰۱۲۳۴۵۶۷۸۹'.indexOf(d))
const a2e = s => s.replace(/[٠-٩]/g, d => '٠١٢٣٤٥٦٧٨٩'.indexOf(d))
const p2a = s => s.replace(/[۰-۹]/g, d => '٠١٢٣٤٥٦٧٨٩'['۰۱۲۳۴۵۶۷۸۹'.indexOf(d)])
const a2p = s => s.replace(/[٠-٩]/g, d => '۰۱۲۳۴۵۶۷۸۹'['٠١٢٣٤٥٦٧٨٩'.indexOf(d)])
// https://stackoverflow.com/a/58157015/10321531
@realamirhe
realamirhe / architect.py
Created July 10, 2025 11:42
create LLM structures from architecture markdown
from pathlib import Path
def parse_tree_structure(tree_str: str):
"""Parse tree-like structure and return list of directories and files as Paths."""
lines = [line.split('#')[0].rstrip() for line in tree_str.strip().splitlines()]
cleaned_lines = [line for line in lines if line.strip()]
paths = []
path_stack = []
@realamirhe
realamirhe / whisper_runner.py
Created July 1, 2025 12:11
run whisper speech to text in the colab
!ffmpeg -i file.m4a file.wav
import os
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
# torch must be loaded after the env setup
import torch
torch.cuda.empty_cache()
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from datasets import load_dataset
@realamirhe
realamirhe / jupyter_root_resolver.py
Created February 3, 2025 12:16
Resolve the root folder for package loading in nested jupyter files for r&d
import sys
import os
while ".gitignore" not in os.listdir():
os.chdir("..")
root_path = os.getcwd()
if root_path not in sys.path:
sys.path.append(root_path)
@realamirhe
realamirhe / BasicTeX-vs code setup.md
Last active August 3, 2025 07:22
setup minimal latex in mac (basicTex and vscode)
  1. Install BasicTeX. pkg or homebrew
  2. Validate installation
which pdflatex
  1. Update the native TeX Live Manager itself and all aviable packages
@realamirhe
realamirhe / Z.tsx
Last active March 14, 2024 08:46
Conditional Render in jsx
/* eslint-disable @typescript-eslint/no-explicit-any */
import {
ReactNode,
RefAttributes,
cloneElement,
createElement,
isValidElement,
} from 'react';
export default function Z() {
@realamirhe
realamirhe / download_youtube_playlist.py
Created October 31, 2023 05:06
download youtube playlist
# !pip install python-slugify pytube -q
from pytube import Playlist
from slugify import slugify
playlist_url = 'https://www.youtube.com/playlist?list=PLUl4u3cNGP63Wy1oqQW2oD2HBdDSY8Ghi'
playlist = Playlist(playlist_url)
print(f'Downloading: {playlist.title}')
output_dir = slugify(playlist.title)
@realamirhe
realamirhe / mac-dns-setter.sh
Created July 26, 2023 11:11
mac dns setter from terminal
function dns {
if [[ $1 == "shecan" ]]
then
networksetup -setdnsservers Wi-Fi 178.22.122.100 185.51.200.2
echo "[Shecan] dns has been set accrodingly"
elif [[ $1 == "radar" ]]
then
networksetup -setdnsservers Wi-Fi 10.202.10.10 10.202.10.11
echo "[Radar game] dns has been set accrodingly"
elif [[ $1 == "electro" ]]
@realamirhe
realamirhe / discord-crawler.js
Created December 27, 2022 08:30
Crawl discord images and text
window.discordRef = Object.keys(window.discordRef).length ? window.discordRef : {};
function debounceEvent(callback, time) {
let interval;
return () => {
clearTimeout(interval);
interval = setTimeout(() => {
interval = null;