Skip to content

Instantly share code, notes, and snippets.

View mohd-akram's full-sized avatar
💼
Looking for work

Mohamed Akram mohd-akram

💼
Looking for work
View GitHub Profile
@mohd-akram
mohd-akram / gh-ssh
Last active April 17, 2024 09:13
Utility to handle creating and using GitHub deploy keys
#!/bin/sh
set -euo pipefail
dir=~/.ssh/github.com
name=$(basename "$0")
help=$(printf "\
usage: %s [-d] [repo]
@mohd-akram
mohd-akram / port-revbump
Created October 9, 2023 14:51
Utility to bump revision of a list of ports (MacPorts)
#!/bin/sh
set -euo pipefail
root=
while getopts D: opt; do
case $opt in
D) root=$OPTARG ;;
?) exit 2
esac
done
@mohd-akram
mohd-akram / foreach2of.js
Last active September 11, 2023 11:00
jscodeshift mod to convert Array.forEach to for-of loop
/** @type {import('jscodeshift').Transform} */
module.exports = function (file, api) {
const j = api.jscodeshift;
const root = j(file.source);
return root
.find(j.CallExpression, { callee: { property: { name: "forEach" } } })
.replaceWith((path) => {
const call = path.value;
const callee = /** @type {import('jscodeshift').MemberExpression} */ (
@mohd-akram
mohd-akram / urls
Created August 3, 2022 19:09
Find URLs in a directory
#!/bin/sh
grep -ro "http[^ )>']*" "$1" | grep -v "[{}]" | cut -d: -f 2- | sort | uniq
@mohd-akram
mohd-akram / mkv2mp4
Last active January 20, 2023 08:26
POSIX shell script to convert MKV file to MP4 using ffmpeg
#!/bin/sh
set -eu
if [ $# = 0 ]; then
printf "usage: %s file [opts]\n" "$(basename "$0")" >&2
exit 2
fi
f=$1
shift
if gpac -i "$f" inspect | grep -q DolbyVision; then
set -- -ab dby1 "$@"
@mohd-akram
mohd-akram / clping
Last active May 10, 2022 10:18
A utility to ping different regions of cloud providers
#!/bin/sh
set -eu
set -o pipefail 2>/dev/null || :
aws_regions="\
af-south-1 ap-east-1 ap-northeast-1 ap-northeast-2 ap-northeast-3
ap-south-1 ap-southeast-1 ap-southeast-2 ca-central-1 eu-central-1 eu-north-1
eu-south-1 eu-west-1 eu-west-2 eu-west-3 me-south-1 sa-east-1 us-east-1
us-east-2 us-west-1 us-west-2
@mohd-akram
mohd-akram / generic
Last active October 31, 2020 10:41
Postfix configuration for sending email via mail/mailx using an email service (eg. Outlook, Gmail)
user name@example.com
@mohd-akram
mohd-akram / ere2bre
Last active September 26, 2020 18:09
A script to convert an ERE (extended regular expression) to one or more BREs
#!/usr/bin/env awk -f
# usage: ere2bre <ere>
function bracket( \
pattern, i, \
c, c2, term, len, end \
) {
++i # skip opening bracket
if (substr(pattern, i, 1) == "]") ++i # skip right bracket
@mohd-akram
mohd-akram / shallow-clone
Last active September 23, 2020 12:54
A script to shallow clone a repository up to the most recent version tag, or a specified tag/ref.
#!/bin/sh
# usage: shallow-clone <url> [ref]
url=$1
ref=$2
repo=$(basename "$url" .git)
head=$(git ls-remote "$url" HEAD | tail -n1 | cut -f1)
if [ ! "$head" ]; then exit 1; fi
if [ "$ref" ]; then
id=$(git ls-remote "$url" "$ref" "$ref^{}" | tail -n1 | cut -f1)
else
@mohd-akram
mohd-akram / icloud-download
Created September 22, 2020 19:56
A script to download files and directories from iCloud Drive
#!/usr/bin/env python3
# Install
# 1. Install dependency: `pip3 install --user pyicloud`
# 2. Sign in to iCloud: `icloud --username your@email.com`
# 3. Copy file to somewhere in your `PATH`
# 4. Add `alias icloud-download="ICLOUD_EMAIL=your@email.com icloud-download"`
# to ~/.profile or ~/.bashrc, etc
# 5. Use via eg. `icloud-download Documents/folder`
# which will download `folder` to your current directory