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 / vm.sh
Last active January 7, 2024 10:38
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-x> 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 April 4, 2021 08:46
A script to build a dynamic Nginx module with the correct configure options.
#!/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 March 30, 2020 13:58
Escape POSIX (grep, sed, ex) regular expression patterns and replacements
#!/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 January 29, 2020 13:07
A script to install VMware tools, xfce and lightdm on a freshly installed FreeBSD system.
#!/bin/sh
username=$1
if [ ! "$username" ]; then
echo usage: $0 username >&2
exit 1
fi
if [ "`id -u`" != 0 ]; then
@mohd-akram
mohd-akram / schotter.c
Created September 13, 2018 15:45
Standalone version of LOLWUT from Redis 5.
/*
* 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
@mohd-akram
mohd-akram / matrix.c
Created January 27, 2014 01:23
Matrix digital rain in C.
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define WIDTH 80
#define HEIGHT 40
#define idx(x, y) ((x)+WIDTH*(y))
@mohd-akram
mohd-akram / query_sort.py
Created January 3, 2013 17:28
An intuitive method to sort results in a few lines (Python)
"""This module sorts a list of results based on a query.
If there is an intersection between words in the query and a result, it
is placed near the beginning of the list (based on length of intersection).
If there is no intersection, the position of the query (substring) in the
result (string) is used for sorting. These results are placed toward the end
of the list.
"""
@mohd-akram
mohd-akram / minesweeper.py
Last active May 4, 2022 03:49
A command line version of Minesweeper in Python
"""A command line version of Minesweeper"""
import random
import re
import time
from string import ascii_lowercase
def setupgrid(gridsize, start, numberofmines):
emptygrid = [['0' for i in range(gridsize)] for i in range(gridsize)]