Skip to content

Instantly share code, notes, and snippets.

View mahmoud's full-sized avatar
Back on the grid!

Mahmoud Hashemi mahmoud

Back on the grid!
View GitHub Profile
@mahmoud
mahmoud / zpool_replace_history.sh
Created November 19, 2018 08:51
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__'
$ python example.py sum --help
Usage: cmd sum [FLAGS]
Just a lil fun in the sum
Flags:
--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
mahmoud / mp4_cut.py
Created January 6, 2018 09:13
a little something i whipped up for cleaner Pyninsula recording cuts
#!/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
@mahmoud
mahmoud / postgres_queue_get.sql
Created January 5, 2018 00:03
postgres queue get
DELETE FROM {table_name}
WHERE id = (
SELECT id
FROM {0}
WHERE deliver_after <= now()
AND q_name IN (SELECT unnest({q_names}))
ORDER BY priority DESC, created_at
FOR UPDATE SKIP LOCKED
LIMIT 1
)
@mahmoud
mahmoud / idna_notes.md
Created January 1, 2018 22:04
some notes on the idna package: https://github.com/kjd/idna/

idna package notes:

  • If a segment of a host (i.e., something in url.host.split('.')) is
    already ascii, idna doesn't perform its usual checks. For instance,
    capital letters are not valid idna2008. The package automatically lowercases.

You'll get something like:

Intro

urllib.unquote doesn't fit Python's paradigms so well:

unquote(u'%C3')
u'\xc3'
unquote('%C3')
'\xc3'