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 / 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));
@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 / 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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[][] = [];
// Code from https://github.com/leighhalliday/generate-og-image/blob/master/src/chromium.ts
// and https://github.com/wesbos/wesbos/blob/master/functions/ogimage/ogimage.js
// and thanks wes.bos for the video on this at https://youtu.be/A0Ww-SU7K5E
exports.handler = async (event, context, callback) => {
const url = event.queryStringParameters.url;
const r = await fetch(
`https://publish.twitter.com/oembed?url=${url}&hide_thread=true`
).then((r) => r.json());
// Code from https://github.com/leighhalliday/generate-og-image/blob/master/src/chromium.ts
// and https://github.com/wesbos/wesbos/blob/master/functions/ogimage/ogimage.js
// and thanks wes.bos for the video on this at https://youtu.be/A0Ww-SU7K5E
async function getScreenshot(html, isDev) {
const options = await getOptions(isDev);
console.log("📸");
const browser = await puppeteer.launch(options);
const page = await browser.newPage();
@mhsattarian
mhsattarian / screenshot_example.js
Last active July 9, 2020 13:43
Using puppeteer-core and chrome-aws-lamba to screenshot a web element
// Code from https://github.com/leighhalliday/generate-og-image/blob/master/src/chromium.ts
// and https://github.com/wesbos/wesbos/blob/master/functions/ogimage/ogimage.js
// and thanks wes.bos for the video on this at https://youtu.be/A0Ww-SU7K5E
const chrome = require("chrome-aws-lambda");
const puppeteer = require("puppeteer-core");
const exePath = "/usr/bin/google-chrome";
async function getOptions(isDev) {
@mhsattarian
mhsattarian / Download-Springer-Free-Ebooks.md
Last active April 30, 2020 19:21
Springer Publications has recently released a huge list of books that are now free to access, Lets grab download links fr

Download Springer Free Ebooks

Springer Publications has recently released a huge list of books that are now free to access, Let's grab download links for them.

Ebook links

List of books is available as an google sheet. you can also use this repository to download them. but, it's a python script to download them and is probably slow and as far as I checked is not using download managers like aria2, so I decided to grab the download links automatically and download them using IDM.