Skip to content

Instantly share code, notes, and snippets.

View e-dreyer's full-sized avatar

Erik Dreyer e-dreyer

View GitHub Profile
@e-dreyer
e-dreyer / test.py
Created October 16, 2023 07:43
test.py
# %% [markdown]
# # Channel Estimation
#
# - The multi-path channel acts as a filter on the transmitted information.
# - The channel impulse response **CIR** has to be estimated to enable the detection algorithms, **DFE** and **MLSE** to estimate the transmitted block or sequence of symbols.
# - This is made possible by transmitting a sequence of known symbols, known as **pilot symbols** or **training symbols**, in the center of the data block.
# - Assuming the **CIR** is time-invariant for the duration of a data block, the **CIR** can be estimated from the **pilot symbols** using a process called **least squares** or **LS** estimation.
#
# \begin{equation}
# S = [s_1, s_2, \dots, p_1, p_2, \dots, p_p, \dots, s_{N-1}, s_{N}]
@e-dreyer
e-dreyer / async_api.py
Created August 24, 2023 06:19
Asyn Iterator for API requests
import time
import random
import asyncio
def randomSleep():
# Blocking sleep function
random_delay = random.uniform(0, 1)
time.sleep(random_delay)
async def randomAsyncSleep():
@e-dreyer
e-dreyer / corrected_implementation.py
Last active August 14, 2023 10:17
Python nested TypedDict example for discuss.python.org
from typing_extensions import TypedDict
from typing import Optional
class NodeDict(TypedDict):
id: str
value: int
parent: Optional['NodeDict'] # No error anymore
parent_node = NodeDict(
id='parent_node_id',
@e-dreyer
e-dreyer / remind_me_bot_example.py
Created August 13, 2023 15:46
RemindMe bot regex testing
import re
pattern = r'(?i)@remindMe\s*(?:(?:(\d+)\s*years?)?\s*)?(?:(\d+)\s*months?)?\s*(?:(\d+)\s*weeks?)?\s*(?:(\d+)\s*days?)?\s*(?:(\d+)\s*hours?)?\s*(?:(\d+)\s*minutes?)?'
tests: list[str] = list([
"@remindMe 3 years 2 months 1 weeks 1 day",
"@remindMe 6 months 2 days",
"@remindMe 7 months 1 day",
"@remindMe 2 weeks",
"@remindMe 1 day",
@e-dreyer
e-dreyer / remove_bad_taste_logo_forced_on_all_users.js
Created August 13, 2023 12:30
Remove ugly techhub.social logo
// ==UserScript==
// @name Remove techhub.social logo from the page
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Remove the annoying logo from the webpage.
// @author https://techhub.social/@Stark9837
// @match https://techhub.social/*
// @grant none
// ==/UserScript==
@e-dreyer
e-dreyer / accumulate.py
Created August 10, 2023 07:20
Python Itertools experiments
from itertools import accumulate
from timeit import default_timer as timer
if __name__ == "__main__":
custom_accumulate_start = timer()
myList = range(0, 10000, 2)
myTotal = 0
myAccumulation = list()
for myItem in myList:
@e-dreyer
e-dreyer / nested_for_loops.py
Last active August 8, 2023 18:39
Improve Python loops with product()
list_a = [1, 2020, 70]
list_b = [2, 4, 7, 2000]
list_c = [3, 70, 7]
for a in list_a:
for b in list_b:
for c in list_c:
if a + b + c == 2077:
print(a, b, c)
@e-dreyer
e-dreyer / exception_handling_with_decorators.py
Last active August 8, 2023 18:43
Example of using decorators to wrap functions for exception handling
def handleMastodonExceptions(func) -> Callable:
"""
This is an exception handler that can be used as a wrapper via a decorator to handle Mastodon.py exceptions.
"""
def wrapper(self, *args, **kwargs):
try:
result = func(self, *args, **kwargs)
return result
except MastodonServerError as e:
logging.critical(f"MastodonServerError: {e}")
@e-dreyer
e-dreyer / configAccessor.py
Created August 3, 2023 10:12
ConfigAccessor ABC Python class
from typing import Any, Dict
import yaml
from collections import UserDict
class ConfigAccessor(UserDict):
def __init__(self, file_name: str) -> None:
super().__init__()
self.file_name = file_name
try:
@e-dreyer
e-dreyer / zip_copy_missing_keys.py
Created August 2, 2023 15:19
Zip copy missing keys
def copy_missing_keys(source_dict, destination_dict):
for key, value in source_dict.items():
if key not in destination_dict:
destination_dict[key] = value
# Sample dictionaries
dict1 = {'key1': 42, 'key2': 10, 'key3': 5}
dict2 = {'key2': 15, 'key4': 23}
# Copy missing keys and values from dict1 to dict2