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 enum, gzip, zlib | |
class Compression(enum.IntEnum): | |
GZIP = 1 # GZip (RFC1952) (unused in practice) | |
ZLIB = 2 # Zlib (RFC1950) | |
NONE = 3 # Uncompressed. Mentioned in the wiki, but unused in practice | |
_compress = { | |
NONE: lambda _: _, |
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
# Is __getattr__ invoked on __iter__ ? | |
# Copyright (C) 2021 Rodrigo Silva (MestreLion) <linux@rodrigosilva.com> | |
# License: GPLv3 or later, at your choice. See <http://www.gnu.org/licenses/gpl> | |
import collections.abc | |
import timeit | |
class MyDict(collections.abc.MutableMapping): | |
def __init__(self, *a, **kw): self._items = dict(*a, **kw) |
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 operator | |
class Point: | |
"""A 3D, (x, y, z) mutable point | |
>>> p1 = Point(1, 2, 3) | |
>>> p1 | |
Point(x=1, y=2, z=3) | |
>>> p2 = Point(1, 2, 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
# https://stackoverflow.com/questions/67803260 | |
from typing import Generic, TypeVar, Dict, Any, Union | |
class DataClassJsonMixin: ... | |
class Person(DataClassJsonMixin): ... | |
JSON = Dict[str, Any] # Good enough json type for this demo | |
T = TypeVar("T", bound=DataClassJsonMixin) | |
# Solution 1: Union with impossible type that takes a Generic | |
# JSONOf = Union[JSON, Dict[JSON, T]] |
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
#!/usr/bin/env python3 | |
# Iter vs Yield vs For | |
# Copyright (C) 2021 Rodrigo Silva (MestreLion) <linux@rodrigosilva.com> | |
# License: GPLv3 or later, at your choice. See <http://www.gnu.org/licenses/gpl> | |
import collections.abc | |
import timeit | |
class Base(collections.abc.MutableMapping): | |
def __init__(self, items: dict = None): self._items: dict = items or {} |
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
#!/bin/bash | |
# Raspberry Pi stress CPU temperature measurement script. | |
# | |
# Download this script (e.g. with wget) and give it execute permissions (chmod +x). | |
# Then run it with ./pi-cpu-stress.sh [run_name] | |
# Variables. | |
test_run=${1:-1} | |
test_results_file="${HOME}/cpu_temp_${test_run}.log" | |
stress_length="10m" |
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
#!/usr/bin/env bash | |
echo "Determining OS..." | |
if [[ "$(uname -s)" == "Linux" ]]; then | |
mcdir="$HOME/.minecraft/" | |
downloader="wget --no-check-certificate -q -O" | |
os="linux" | |
natives="libjinput-linux libjinput-linux64 liblwjgl liblwjgl64 libopenal libopenal64" | |
elif [[ "$(uname -s)" == "Darwin" ]]; then |
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
#!/bin/bash -e | |
#### | |
# Helper script to update the Last modified timestamp of files in a Git SCM | |
# Projects working Copy | |
# | |
# When you clone a Git repository, it sets the timestamp of all the files to the | |
# time when you cloned the repository. | |
# | |
# This becomes a problem when you want the cloned repository, which is part of a | |
# Web application have a proper cacheing mechanism so that it can re-cache files |