Skip to content

Instantly share code, notes, and snippets.

View mirismaili's full-sized avatar

S. Mahdi Mir-Ismaili mirismaili

View GitHub Profile
@mirismaili
mirismaili / eslint.config.js
Last active November 16, 2023 14:13
ESLint flat config for next.js. But incomplete yet. See: https://github.com/vercel/next.js/discussions/49337#discussioncomment-7588601
import nextPlugin from '@next/eslint-plugin-next'
import tsPlugin from '@typescript-eslint/eslint-plugin'
import tsParser from '@typescript-eslint/parser'
import prettierConfig from 'eslint-config-prettier'
import importPlugin from 'eslint-plugin-import'
import prettierPlugin from 'eslint-plugin-prettier'
import reactPlugin from 'eslint-plugin-react'
import hooksPlugin from 'eslint-plugin-react-hooks'
/** @type {import('eslint').Linter.FlatConfig[]} */
@mirismaili
mirismaili / persist-data.js
Last active April 21, 2023 14:54
A gateway for the standard `localStorage` that provides easier and more flexible interface to it
// CAVEAT: Importing this file has side effects. See the below `setInterval()`.
const lStorageCache = {}
const sStorageCache = {}
/**
* @param {Storage} storage
* @returns {ProxyHandler<{}>}
*/
function proxyHandlers(storage) {
@mirismaili
mirismaili / lang-codes.d.ts
Last active April 11, 2023 12:15
ISO 639-1 standard language codes (typescript)
/**
* **ISO 639-1 standard language codes**
*
* To regenerate, run this query:<br>
* <code>
* [...document.querySelector('#Table > tbody').children].map(tr => `'${tr.children[1].innerText}'`).sort().join('|')
* </code><br>
* on {@link https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes this page}.
* @See {@link https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes}
*/
@mirismaili
mirismaili / post-commit
Created March 12, 2023 20:36
Auto tag current version (from package.json) after commit
#!/bin/bash
# Auto-tag version (if already not existed):
version=$(grep -oP '\"version\"\s*:\s*\"\K\d+\.\d+\.\d+' package.json) # extract `version` from "package.json". ex: 2.0.4
git tag v$version 2>/dev/null # ex: `git tag v2.0.4` (and ignore possible error)
exit 0
@mirismaili
mirismaili / post-commit
Last active March 12, 2023 20:36
Auto tag current version (from package.json) after commit
#!/bin/bash
#X # ATTENTION: YOU NEED TO FIRST PUT `build-version: 0` FIELD IN YOUR "package.json" FILE!
version=$(grep -oP '\"version\"\s*:\s*\"\K\d+\.\d+\.\d+' package.json) # extract `version` from "package.json". ex: 2.0.4
git tag v$version 2>/dev/null # ex: `git tag v2.0.4` # Auto tag version if needed (if not already existed).
#X # Calculate `buildVersion`:
#X
#X currentCommitNum=$(git rev-list --count HEAD 2>/dev/null || echo 0)
@mirismaili
mirismaili / digital-signature.js
Last active June 29, 2022 19:10
Sign (using private key) and Verify (using public key) in node.js #cryptography
import {createPrivateKey, generateKeyPairSync, sign, verify} from 'node:crypto'
const passphrase = 'passphrase'
const {publicKey, privateKey} = generateKeyPairSync('ed25519', {
privateKeyEncoding: {format: 'pem', type: 'pkcs8', cipher: 'aes-256-cbc', passphrase},
publicKeyEncoding: {format: 'pem', type: 'spki'},
})
console.log(privateKey, publicKey)
const message = 'Hello world!'
@mirismaili
mirismaili / user-agents.json
Created April 20, 2022 21:03
Sample user-agents
{
"Chrome": [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/100.0.4896.85 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (iPad; CPU OS 15_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/100.0.4896.85 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (iPod; CPU iPhone OS 15_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/100.0.4896.85
/**
* Created on 1400/11/5 (2022/1/25).
* @author {@link https://mirismaili.github.io S. Mahdi Mir-Ismaili}
*/
/**
* @see https://stackoverflow.com/a/3540295/5318303
* @type {boolean}
*/
export const isMobileDevice =
@mirismaili
mirismaili / vazir-font.js
Created January 19, 2022 13:38
vazir font variants
import vazirBlackWoff2 from './Vazir-Black.woff2'
import vazirBoldWoff2 from './Vazir-Bold.woff2'
import vazirLightWoff2 from './Vazir-Light.woff2'
import vazirMediumWoff2 from './Vazir-Medium.woff2'
import vazirThinWoff2 from './Vazir-Thin.woff2'
import vazirWoff2 from './Vazir.woff2'
/**
* Created on 1399/8/30 (2020/11/20).
* @author {@link https://mirismaili.github.io S. Mahdi Mir-Ismaili}
@mirismaili
mirismaili / .editorconfig
Last active August 11, 2022 14:10
Editor Configuraion File
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 2
trim_trailing_whitespace = false # disable due to IntellijIdea 2021.1.1 bug: https://stackoverflow.com/questions/2977324/disable-reformatting-code-when-saving-files#comment119066928_2978824
ij_continuation_indent_size = 2