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
mahmoud / basic_argparse_framework.py
Last active May 1, 2019
(based on years of argparse experience, also serves to demonstrate why argparse is not so good)
View basic_argparse_framework.py
def create_parser():
root_parser = ArgumentParser(description='article fetch operations')
root_parser.add_argument('--list_home', help='list lookup directory')
add_subparsers(root_parser.add_subparsers())
return root_parser
def add_subparsers(subparsers):
parser_list = subparsers.add_parser('list')
parser_list.add_argument('target_list', nargs='?',
View list_meets_tuple.py
>>> 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]
View get_leaf_paths.py
# https://twitter.com/hynek/status/1076048147074478080
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
mahmoud / migration_checker.sh
Last active Jan 24, 2019
Just a little thing to look for (potentially conflicting) migration changes across all branches. (linux/mac os/bsd compatible)
View migration_checker.sh
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
mahmoud / zpool_replace_history.sh
Created Nov 19, 2018
first zpool replace on ubuntu
View zpool_replace_history.sh
# 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
View old_style_class.py
>>> class Lol:
... pass
...
>>> Lol()
<__main__.Lol instance at 0x7fb2bde403b0>
>>> x = Lol()
>>> x
<__main__.Lol instance at 0x7fb2bde403f8>
>>> x.__class__
<class __main__.Lol at 0x7fb2bde2ce88>
View generator_frame.py
>>> 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 example.py sum --help
Usage: cmd sum [FLAGS]
Just a lil fun in the sum
Flags:
--flagfile FLAGFILE (defaults to None)
--help / -h
View ip_address_notes.md

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
mahmoud / mp4_cut.py
Created Jan 6, 2018
a little something i whipped up for cleaner Pyninsula recording cuts
View mp4_cut.py
#!/usr/bin/env python
"""
./cut_mp4.py --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.