Skip to content

Instantly share code, notes, and snippets.

View thehesiod's full-sized avatar
🎯
Focusing

Alexander Mohr thehesiod

🎯
Focusing
View GitHub Profile
@thehesiod
thehesiod / moto_service.py
Last active October 27, 2020 07:07
Moto Service Helper Class
import asyncio
import functools
import logging
import os
import threading
import socket
import http.server
from typing import Dict, Any, Optional
# Third Party
@thehesiod
thehesiod / audi_manual_downloader.py
Created August 5, 2019 06:57
Audi Manual Downloader
import requests
import shutil
def download_manual():
# three digit page number
code = 'aa99bbcc-110b-999a-9a11-bb99b9aa1d99' # example, will not work
url = "https://webcat.lex-com.net/AudiBordbuch/docs/{code}/files/assets/common/page-html5-substrates/page0{page_num:03d}_4.jpg?uni=c91d23879402ccf1e95bc4acbec392e4"
# low rez
@thehesiod
thehesiod / netcdf_mem_file_test.py
Created December 21, 2018 02:30
netCDF Processing Error test
import requests
import netCDF4
import gzip
import tempfile
import traceback
import os.path
import glob
def test_cdf_bytes(cdf_compressed_bytes: bytes):
@thehesiod
thehesiod / calendar_bug.py
Last active October 10, 2018 06:05
Google Calendar bug with recurring events
from googleapiclient import discovery
import httplib2
from oauth2client.service_account import ServiceAccountCredentials
calendar_id = 'user@host.com'
resource_calendar_id = 'resourceUser@resource.calendar.google.com'
def get_delegated_endpoint(base_creds: ServiceAccountCredentials, user_email: str):
creds = base_creds.create_delegated(user_email)
http = httplib2.Http(timeout=15)
@thehesiod
thehesiod / test_leak.py
Last active September 19, 2018 22:52
aiobotocore / botocore leak test script
#!/usr/bin/env python3
import botocore.exceptions
import botocore.session
import tracemalloc
import aiobotocore.session
import gc
import os
import time
import sys
import asyncio
@thehesiod
thehesiod / aio_rate_limiter.py
Last active September 14, 2018 07:17
asyncio sliding window rate limiter
import asynctest
import asyncio
import logging
from collections import deque
class RateLimiter:
class Error(Exception):
pass
@thehesiod
thehesiod / upvote_aiohttp.py
Created August 29, 2018 12:42
upvote aiohttp client
import asyncio
import argparse
import logging
import functools
# Third Party
from google.oauth2 import service_account
from google.oauth2 import _client
from google.auth import transport
from google.auth.transport import requests as gauth_requests
@thehesiod
thehesiod / upvote_client.py
Created August 28, 2018 17:00
google upvote client
import argparse
from collections import defaultdict
from datetime import datetime, timedelta
import sys
import os
import logging
from google.cloud import datastore
from google.appengine.ext import ndb
@thehesiod
thehesiod / asyncio_generator_issue.py
Created August 1, 2018 21:21
asyncio generator issue
import asyncio
async def generator_fn():
print(f" enter generator {id(asyncio.Task.current_task())}")
try:
while True:
yield
except:
@thehesiod
thehesiod / s3_relay.py
Last active April 4, 2018 07:08
S3 Latency Limiter, parallel get_object wrapper
import asyncio
import logging
from typing import List
def _ignore_task_exception(task: asyncio.Future, logger: logging.Logger):
# noinspection PyBroadException
try:
task.result()
except BaseException: