View conftest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Common test fixtures for pytest | |
""" | |
from __future__ import print_function, unicode_literals | |
import os | |
from itertools import groupby | |
import pytest |
View design.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
before = \ | |
''' | |
Traceback (most recent call last): | |
File "tmp.py", line 9, in _make_stack | |
glom(target, spec) | |
File "/home/mahmoud/projects/glom/glom/core.py", line 2024, in glom | |
raise err | |
glom.core.PathAccessError: error raised while processing, details below. | |
Target-spec trace (most recent last): |
View py3_except.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python3 | |
Python 3.7.7 (default, Mar 10 2020, 17:25:08) | |
[GCC 5.4.0 20160609] on linux | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> e = 'hi' | |
>>> try: | |
... 1/0 | |
... except Exception as e: | |
... pass | |
... |
View py3_partials.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def f(a, b): | |
... return a, b | |
... | |
# py27 | |
>>> partial(f, b=1)(1, 2) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: f() got multiple values for keyword argument 'b' |
View basic_argparse_framework.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
View migration_checker.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '{}'"' \; |
View zpool_replace_history.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class Lol: | |
... pass | |
... | |
>>> Lol() | |
<__main__.Lol instance at 0x7fb2bde403b0> | |
>>> x = Lol() | |
>>> x | |
<__main__.Lol instance at 0x7fb2bde403f8> | |
>>> x.__class__ | |
<class __main__.Lol at 0x7fb2bde2ce88> |
NewerOlder