Skip to content

Instantly share code, notes, and snippets.

Probably on the train.

Mahmoud Hashemi mahmoud

Probably on the train.
Block or report user

Report or block mahmoud

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mahmoud /
Last active May 1, 2019
(based on years of argparse experience, also serves to demonstrate why argparse is not so good)
def create_parser():
root_parser = ArgumentParser(description='article fetch operations')
root_parser.add_argument('--list_home', help='list lookup directory')
return root_parser
def add_subparsers(subparsers):
parser_list = subparsers.add_parser('list')
parser_list.add_argument('target_list', nargs='?',
>>> x = [1]
>>> y = (2, 3)
>>> x + y
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate list (not "tuple") to list
>>> x += y
>>> x
[1, 2, 3]
from boltons.iterutils import remap
DATA = {"a": {"b": 1, "c": {"d": 2}}}
OUT = ["a.b", "a.c.d"]
def get_leaf_paths(root, with_val=False):
mahmoud /
Last active Jan 24, 2019
Just a little thing to look for (potentially conflicting) migration changes across all branches. (linux/mac os/bsd compatible)
find . -type d -name migrations -print0 -exec sh -c 'echo && echo "Checking: '{}'" && git --no-pager log --exit-code --all --not master --stat --pretty=format:"%n%ad - %d - %an: %s" --no-merges --after="one week ago" -- '{}' && echo "No changes for: '{}'" || echo "Finished: '{}'"' \;
mahmoud /
Created Nov 19, 2018
first zpool replace on ubuntu
# needs to be parted'd before replacing.
$ sudo parted /dev/disk/by-id/ata-HGST_HDN724030ALE640_PK2234P9K09E0Y
GNU Parted 3.2
Using /dev/sdh
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel GPT
(parted) quit
# then we need to make the ashift=9 because this is an older zfs pool
$ sudo zpool replace -o ashift=9 liu 18069869553946727791 /dev/disk/by-id/ata-HGST_HDN724030ALE640_PK2234P9K09E0Y
>>> class Lol:
... pass
>>> Lol()
<__main__.Lol instance at 0x7fb2bde403b0>
>>> x = Lol()
>>> x
<__main__.Lol instance at 0x7fb2bde403f8>
>>> x.__class__
<class __main__.Lol at 0x7fb2bde2ce88>
>>> z.gi_frame
<frame object at 0x7f21213b7548>
>>> z.__dict__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'generator' object has no attribute '__dict__'
>>> z.__slots__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'generator' object has no attribute '__slots__'
View help.txt
$ python sum --help
Usage: cmd sum [FLAGS]
Just a lil fun in the sum
--flagfile FLAGFILE (defaults to None)
--help / -h

URLs and IPs

The URL standard is one which builds on IP standards. Operating systems also build on IP standards. Believe it or not, the two diverge in some surprising ways!

Hyperlink aims to do some validation of IPs contained within URLs with IP hosts. URLs support a subset of IP syntax, as well as making affordances for future versions of IPs beyond IPv6 (no matter how unfathomable that may seem).

mahmoud /
Created Jan 6, 2018
a little something i whipped up for cleaner Pyninsula recording cuts
#!/usr/bin/env python
./ --input input.mp4 --start 00:00:01 --end 00:00:02 --no-align-keyframes --output output.mp4
import os
import sys
import argparse
import datetime
import subprocess
You can’t perform that action at this time.