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 / areaToTableSpec.ts
Created July 31, 2021 18:36
Generate an object describing a table row and cells (with `colspan` an `rowspan` support) from a text representing cells like CSS grid areas.
interface ITableCellSpec {
id: string;
rows: number;
columns: number;
origin: { rowIndex: number; cellIndex: number };
}
const areaToTableSpec = (arr: string[][]) => {
const output: ITableCellSpec[][] = [];
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mhsattarian
mhsattarian / wsl2-port-forward.ps1
Created October 24, 2021 12:05
WSL2 Port Forwarding using `netsh`.
# credits:
# 1. https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723
# 2. https://dev.to/vishnumohanrk/wsl-port-forwarding-2e22
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
@mhsattarian
mhsattarian / install-php5.6-ubuntu.sh
Last active December 18, 2021 09:52
Install php 5.6 and composer in ubuntu +18.04 (also WSL2)
# install php5.6
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php5.6
php --version
# install required php plugins
sudo apt install php5.6-curl php5.6-xml php5.6-mbstring
@mhsattarian
mhsattarian / tooltip-floating-ui.js
Created December 25, 2021 22:00
A simple tooltip implementation using floating-ui lib
// import $ from 'https://cdn.skypack.dev/cash-dom';
import { computePosition, offset } from 'https://cdn.skypack.dev/@floating-ui/dom@0.1.7';
const tooltip = document.createElement('div');
tooltip.id = 'tooltip';
tooltip.setAttribute('role', 'tooltip');
const tooltipArrow = document.createElement('div');
tooltipArrow.id = 'arrow';
@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));
@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 / 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 / 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.