Skip to content

Instantly share code, notes, and snippets.


Mohamed Akram mohd-akram

View GitHub Profile
mohd-akram / clping
Created Mar 13, 2021
A utility to ping different regions of cloud providers
View clping
# usage: clping [ aws | docean | linode | oracle ...]
set -eu
set -o pipefail 2>/dev/null || :
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 / generic
Last active Oct 31, 2020
Postfix configuration for sending email via mail/mailx using an email service (eg. Outlook, Gmail)
View generic
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 / 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
# usage: shallow-clone <url> [ref]
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)
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`
# 3. Copy file to somewhere in your `PATH`
# 4. Add `alias icloud-download=" 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 /
Last active Oct 21, 2020
A shell function to simplify using docker (vagrant-like experience)
# 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 /
Last active Apr 4, 2021
A script to build a dynamic Nginx module with the correct configure options.
# A script to build a dynamic Nginx module with the correct configure options.
set -eu
set -o pipefail 2>/dev/null || :
if [ ! "$dir" ]; then
mohd-akram /
Last active Mar 30, 2020
Escape POSIX (grep, sed, ex) regular expression patterns and replacements
# 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 /
Created Jan 29, 2020
A script to install VMware tools, xfce and lightdm on a freshly installed FreeBSD system.
if [ ! "$username" ]; then
echo usage: $0 username >&2
exit 1
if [ "`id -u`" != 0 ]; then
mohd-akram / schotter.c
Created Sep 13, 2018
Standalone version of LOLWUT from Redis 5.
View schotter.c
* Copyright (c) 2018, Salvatore Sanfilippo <antirez at gmail dot com>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright