Skip to content

Instantly share code, notes, and snippets.

Avatar

Mohamed Akram mohd-akram

View GitHub Profile
@mohd-akram
mohd-akram / mkv2mp4
Created Jul 20, 2021
POSIX shell script to convert MKV file to MP4 using ffmpeg
View mkv2mp4
#!/bin/sh
set -eu
if [ $# = 0 ]; then
printf "usage: %s file [opts]\n" "$(basename "$0")" >&2
exit 2
fi
f=$1
shift
ffmpeg -i "$f" -c copy -scodec mov_text -map 0 "$@" "${f%.*}.mp4"
@mohd-akram
mohd-akram / clping
Created Mar 13, 2021
A utility to ping different regions of cloud providers
View clping
#!/bin/sh
# usage: clping [ aws | docean | linode | oracle ...]
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
@mohd-akram
mohd-akram / generic
Last active Oct 31, 2020
Postfix configuration for sending email via mail/mailx using an email service (eg. Outlook, Gmail)
View generic
user name@example.com
@mohd-akram
mohd-akram / ere2bre
Last active Sep 26, 2020
A script to convert an ERE (extended regular expression) to one or more BREs
View ere2bre
#!/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 Sep 23, 2020
A script to shallow clone a repository up to the most recent version tag, or a specified tag/ref.
View shallow-clone
#!/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 Sep 22, 2020
A script to download files and directories from iCloud Drive
View icloud-download
#!/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
@mohd-akram
mohd-akram / vm.sh
Last active Oct 21, 2020
A shell function to simplify using docker (vagrant-like experience)
View vm.sh
# Add to ~/.profile or ~/.bashrc, etc
# Use it like:
# vm add ubuntu # or vm add ubuntu custom/ubuntu
# vm sh ubuntu
# <ctrl-d> to detach from shell
# vm sh ubuntu # returns to the same shell
# vm stop ubuntu && vm rm ubuntu
vm() {
case $1 in
ls) docker ps -a ;;
@mohd-akram
mohd-akram / build-nginx-module.sh
Last active Apr 4, 2021
A script to build a dynamic Nginx module with the correct configure options.
View build-nginx-module.sh
#!/bin/sh
# A script to build a dynamic Nginx module with the correct configure options.
set -eu
set -o pipefail 2>/dev/null || :
dir="$1"
if [ ! "$dir" ]; then
@mohd-akram
mohd-akram / escape-strings.sh
Last active Mar 30, 2020
Escape POSIX (grep, sed, ex) regular expression patterns and replacements
View escape-strings.sh
#!/bin/sh
# Functions to escape strings for use in utilities like grep, sed and ex
# Examples
# grep "$(bre "$foo")" file
# sed "s/$(ptrn "$foo")/$(repl "$bar")/g" file
# echo "s/$(exptrn "$foo")/$(exrepl "$bar")/g | %p | q" | ex file
bre() {
@mohd-akram
mohd-akram / freebsd-vmware.sh
Created Jan 29, 2020
A script to install VMware tools, xfce and lightdm on a freshly installed FreeBSD system.
View freebsd-vmware.sh
#!/bin/sh
username=$1
if [ ! "$username" ]; then
echo usage: $0 username >&2
exit 1
fi
if [ "`id -u`" != 0 ]; then