Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Blake VandeMerwe blakev

🎯
Focusing
View GitHub Profile
@blakev
blakev / filters.py
Last active Jul 22, 2022
Django admin.ModelAdmin `list_filter` meta type classes for relative time and boolean values
View filters.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# >>
# vidangel-backend, 2022
# Blake VandeMerwe <blake@vidangel.com>
# <<
import re
from datetime import timedelta
@blakev
blakev / slack_handler.py
Last active Jul 14, 2022
Python logging handler for publishing to a slack channel.
View slack_handler.py
import os
import time
import json
import socket
import logging
from slacker import Slacker, Error as SlackerError
class SlackChannelHandler(logging.Handler):
@blakev
blakev / r-pihole_top10.txt
Last active May 8, 2022
/r/pihole's Top 10 blocklist. 2020-04-07
View r-pihole_top10.txt
# Compilation of r/pihole User's Top-10 blocked domains.
ssl-bbcsmarttv.2cnt.net
tlx.3lift.com
graph.accountkit.com
app.adjust.com
ib.adnxs.com
fls-na.amazon.com
mads.amazon.com
unagi-na.amazon.com
@blakev
blakev / base_query_validator.py
Created Jul 19, 2021
FastAPI Query parameter fixer/validators
View base_query_validator.py
from inspect import signature
from http import HTTPStatus
from logging import getLogger
from functools import wraps, partial
from typing import Dict, Callable, TypeVar, Optional
from fastapi import HTTPException
from fastapi.params import Query
T = TypeVar('T')
@blakev
blakev / display.py
Created May 2, 2021
Simple Python3 "driver" for the WaveShare PoE Pi HAT with LCD display.
View display.py
import time
from typing import Optional, List
from PIL import Image
from PIL import ImageDraw
from PIL import ImageOps
from PIL import ImageFont
from smbus import SMBus
@blakev
blakev / ksl.py
Last active Mar 18, 2021
Command line application to search KSL Classifieds
View ksl.py
import re
import argparse
import concurrent.futures
import string
from collections import namedtuple
from urllib.request import urlopen
from urllib.parse import urlencode
from bs4 import BeautifulSoup
@blakev
blakev / assembler.py
Created Dec 2, 2014
Assembler and VM written in Python
View assembler.py
#!/usr/bin/env python
import sys, os, re
errorDict = {
0: "Default error for, %s"
}
warningDict = {
0: "Default warning for, %s",
100:"%s Label already found in symbol table."
@blakev
blakev / ssh_util.py
Last active May 1, 2019
Paramiko SSHClient Abstraction, includes batch commands and stdin
View ssh_util.py
# Paramiko SSH Object with batch commands and stdin
# Blake VandeMerwe July 2014
#
# Adapted from Joe Linoff's code at http://joelinoff.com/blog/?p=905
# his did not work for me, so I fixed it and added some features.
#
import re
import string
import logging
import socket
@blakev
blakev / background_tasks.py
Last active Oct 19, 2017
Background tasks manager for gevent Greenlets
View background_tasks.py
#!/usr/bin/env python3
# ~*~ coding: utf-8 ~*~
#
# >>
# .. created: 5/20/16
# .. author: blake.vandemerwe
#
# LICENSE
# <<
View map_join_str.py
import timeit
print(timeit.Timer("'+'.join([str(x) for x in range(10000)])").repeat(3, 1000))
print(timeit.Timer("'+'.join(map(str, range(10000)))").repeat(3, 1000))
# [1.843802978983149, 1.838354193023406, 1.8291272450005636]
# [1.4447947760345414, 1.442527316045016, 1.4384180280612782]