Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Alexander Mohr thehesiod

🎯
Focusing
View GitHub Profile
@thehesiod
thehesiod / android_dcim_cleanup.py
Last active Dec 6, 2020
Delete Empty Android DCIM folders
View android_dcim_cleanup.py
# requires webdav connection (see WebDAV Server app, and ensure port is not 8080)
from pathlib import Path
import shutil
def main():
cam_path = Path('//192.168.1.186@8081/DavWWWRoot/DCIM/Camera')
for idx, item in enumerate(cam_path.iterdir()):
if idx % 100 == 0:
print(f"Processing folder {idx}")
@thehesiod
thehesiod / freeze_time.sql
Created May 20, 2020
fake/mock now on postgres DB
View freeze_time.sql
-- inspiration from https://dba.stackexchange.com/questions/69988/how-can-i-fake-inet-client-addr-for-unit-tests-in-postgresql/70009#70009
CREATE SCHEMA if not exists override;
create table if not exists override.freeze_time_param_type
(
param_type text not null primary key
);
insert into override.freeze_time_param_type values ('enabled'), ('timestamp'), ('tick') on conflict do nothing;
View botocore_assume_role.py
import asyncio
import os
import time
import logging
from multiprocessing import Process, Queue
from queue import Empty
import botocore.session
from botocore.credentials import Credentials, CredentialResolver, CredentialProvider, AssumeRoleProvider
View audi_manual_downloader.py
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 Dec 21, 2018
netCDF Processing Error test
View netcdf_mem_file_test.py
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 Oct 10, 2018
Google Calendar bug with recurring events
View calendar_bug.py
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 / 1pass_dups.py
Last active Jul 2, 2020
1password duplicate remover (alpha, only run in debugger with breakpoints everywhere *g*)
View 1pass_dups.py
#!/usr/bin/env python3
import json
import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor
import html
import dictdiffer
import iso8601
@thehesiod
thehesiod / upvote_aiohttp.py
Created Aug 29, 2018
upvote aiohttp client
View upvote_aiohttp.py
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 Aug 28, 2018
google upvote client
View upvote_client.py
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
View asyncio_generator_issue.py
import asyncio
async def generator_fn():
print(f" enter generator {id(asyncio.Task.current_task())}")
try:
while True:
yield
except: