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 Safety: | |
"""Context manager that catches and reports all exceptions. | |
Use this to catch and report exceptions around non-critical | |
code. | |
""" | |
def __init__(self, reporter=None): | |
""" | |
:param reporter A function that gets called with |
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
tg_foo_bar = TargetGroupArn( | |
"arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/foo-bar/abc123" | |
) | |
# generate a new ARN from the first one | |
tg_baz_quz = TargetGroupArn( | |
target_group_arn, | |
name="baz-qux", | |
internal_id="def456", | |
) |
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 describe_target_group(arn: TargetGroupArn): | |
# at this point, we know "arn" is a valid ARN | |
return client.describe_target_groups( | |
TargetGroupArns=[str(arn)] | |
) |
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
TargetGroupArn("not an ARN") # raises arn.InvalidArnException |
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
from arn.elbv2 import TargetGroupArn | |
target_group_arn_str = ( | |
"arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/foo-bar/abc123" | |
) | |
target_group_arn = TargetGroupArn(target_group_arn_str) | |
# use the ARN instance's __str__ to format the ARN back into a string | |
assert str(target_group_arn) == target_group_arn_str |
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 pk_or_instance(fn): | |
try: | |
first_param_name = next(iter(inspect.signature(fn).parameters)) | |
except StopIteration: | |
raise ValueError(f"Function {fn} needs to take at least one parameter") | |
type_hints = get_type_hints(fn, fn.__globals__) | |
model_type = type_hints.get(first_param_name) | |
if not model_type: | |
raise ValueError( |
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
(function(){debugger; console.log(window.localStorage)})() |
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
prompt_context() { | |
} | |
prompt_dir () { | |
prompt_segment blue black '$' | |
} | |
RSEGMENT_SEPARATOR="\ue0b2" | |
rprompt_segment() { |