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
$XONSH_SHOW_TRACEBACK = True | |
$PROMPT_COMMAND = 'history -a' | |
$HISTSIZE = 25000 | |
$HISTCONTROL = 'ignoreboth' | |
$CLICOLOR = 1 | |
$EDITOR = 'vim' | |
$HOMEBREW_NO_ENV_HINTS = 1 | |
$PROJECTS = '~/projects' | |
$GOPATH = $PROJECTS + '/go' |
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 SingletonMixin: | |
""" Threading safe singleton mixin class. Will run __init__ on subclasses for every | |
invocation, so check self._initialized from __init__ to get around this if not desired. | |
Use: | |
class MyClass(SingletonMixin): | |
def __init__(self): | |
if not self._initialized: | |
# initialize here | |
self.foo = 'bar' |
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
# An opinionated approach to logging in Python | |
import logging | |
import sys | |
def setup_logger(name: str | None = None, | |
level: str | int = 'WARN', | |
log_format: str | None = None) -> logging.Logger: | |
"""Sets up an opinionated logger bifurcating on log level to send | |
error and warning logs to stderr, info and debug to stdout |
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
import collections | |
def infinidict(*args, **kwargs): | |
""" Magical defaultdict that allows key assignments to an aribtrary depth | |
Example: | |
d = infinidict() | |
d['foo']['bar']['baz'] == 'quux' | |
d['foo']['bar']['baz'] # result is 'quux' | |
""" |
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 typing import AsyncIterable | |
async def enumerate_async[T](iterable: AsyncIterable[T], start=0) -> tuple[int, T]: | |
counter = start | |
async for item in iterable: | |
yield counter, item | |
counter += 1 | |
# example usage |
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
import argparse | |
import pathlib | |
from typing import IO, Self | |
class LazyFileType(argparse.FileType): | |
"""Subclasses `argparse.FileType` in order to provide a way to lazily open | |
files for reading/writing from arguments. Initializes the same as the | |
parent, but provides `open` method which returns the file object. | |
Usage: |
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 Chdir: | |
def __init__(self, chdir: str | pathlib.Path): | |
self._pwd = os.getcwd() | |
self._chdir = chdir | |
def __enter__(self): | |
os.chdir(self._chdir) | |
return self | |
def __exit__(self, exc_type, exc_val, exc_tb): |
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://sylvan.apple.com/Aerials/2x/Videos/comp_CH_C007_C011_PSNK_v02_HDR_FINAL_20180709_HDR_4K_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/comp_CH_C002_C005_PSNK_v05_HDR_FINAL_20180709_HDR_4K_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/comp_CH_C007_C004_PSNK_v02_HDR_FINAL_20180709_HDR_4K_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/comp_C004_C003_PS_v01_HDR_PS_20180925_HDR_4K_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/comp_C003_C003_PS_v01_HDR_PS_20180925_HDR_4K_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/comp_C001_C005_PS_v01_HDR_PS_20180925_HDR_4K_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/DB_D008_C010_4K_HDR_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/comp_DB_D008_C010_PSNK_v21_HDR_PS_20180914_F0F16157_HDR_4K_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/DB_D001_C001_4K_HDR_HEVC.mov | |
https://sylvan.apple.com/Aerials/2x/Videos/comp_DB_D001_C001_PSNK_v06_HDR_PS_20180824_HDR_4K_HEVC.mov |
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
# Import Flask, Jsonify and Requests | |
from flask import Flask, jsonify, request | |
# Create the web applicatiion via Flask | |
app = Flask(__name__) | |
# Existing To-Do List | |
# it's easiest to manipulate if this is a dict where key is the id and value is the todo | |
todos = { | |
1: "Buy Hitman 3", |
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
import argparse | |
import functools | |
import logging | |
import os | |
import signal | |
import sys | |
import time | |
_LOG_FORMAT = "%(levelname)s:%(asctime)s:%(name)s:%(message)s" | |
logging.basicConfig(stream=sys.stdout, format=_LOG_FORMAT) |
NewerOlder