Skip to content

Instantly share code, notes, and snippets.

@zevaverbach
zevaverbach / convert_sqlalchemy_model_to_table_str.py
Created October 27, 2021 11:06
Some spaghetti to produce a SQLAlchemy Table *string* from a SQLA model.
import re
from black import format_str, FileMode
def convert_tablemapping_to_table_object(model) -> str:
schema_name = model.__table_args__["schema"].lower()
table_repr = repr(model.__table__)
header_str, *columns = table_repr.split("Column(")
# from https://stackoverflow.com/a/4145486/4386191
@zevaverbach
zevaverbach / battlesnake_typed_dicts.py
Created October 14, 2021 20:16
TypedDicts for Battlesnake /move endpoint
from dataclasses import dataclass
from types import TypedDict, Annotated, Literal
class Squad(TypedDict):
allowBodyCollisions: bool
sharedElimination: bool
sharedHealth: bool
sharedLength: bool
// Copyright 2013 Soundslice LLC. License: BSD.
/* HTML example: ****************
<figure class="vid">
<video preload>
<source src="/videos/help/playhead.mp4" type="video/mp4">
<source src="/videos/help/playhead.webm" type="video/webm">
</video>
<p>To move the playhead, click in the timeline or drag the playhead’s diamond.</p>
@zevaverbach
zevaverbach / imapflow.d.ts
Created May 16, 2021 20:12
ImapFlow Type Declaration File -- not complete
declare module "imapflow" {
type SequenceString = string;
export interface FetchQueryObject {
uid?: boolean;
flags?: boolean;
bodyStructure?: boolean;
envelope?: boolean;
internalDate?: boolean;
size?: boolean;
@zevaverbach
zevaverbach / pre-commit
Created December 29, 2020 21:20
A Python script and a pre-commit hook that calls it for validating all the HTML files in a directory (recursively) on commit.
# this goes in your local Git repo at .git/hooks/pre-commit
#!/bin/sh
errors=0
for i in $(find . -type f -name "*.html")
do
printf "$i:\n"
validate $i
exit_status=$?
if [ "${exit_status}" -ne 0 ];
@zevaverbach
zevaverbach / .gitignore
Last active June 11, 2020 09:00
.gitignore for Python and PyCharm
.idea/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
@zevaverbach
zevaverbach / keybase.md
Created December 12, 2019 09:34
keybase.md

Keybase proof

I hereby claim:

  • I am zevaverbach on github.
  • I am zevaverbach (https://keybase.io/zevaverbach) on keybase.
  • I have a public key ASDFp0pk3r5jKegFIBveoZdojkoGIP6lUWFFhKSMhtSGmQo

To claim this, I am signing this object:

@zevaverbach
zevaverbach / bundle.js
Last active December 6, 2019 10:14
bundle.js from sveltejs/template (svelte 3.0.0)
(function(l, r) { if (l.getElementById('livereloadscript')) return; r = l.createElement('script'); r.async = 1; r.src = '//' + (window.location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1'; r.id = 'livereloadscript'; l.head.appendChild(r) })(window.document);
var app = (function () {
'use strict';
function noop() { }
function add_location(element, file, line, column, char) {
element.__svelte_meta = {
loc: { file, line, column, char }
};
@zevaverbach
zevaverbach / get_media_file_metadata.py
Created August 8, 2019 08:29
Get metadata from media files using ffprobe and Python
"""
MIT License
Copyright (c) 2019 Zev Averbach
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@zevaverbach
zevaverbach / transcripts_from_yt.py
Last active August 6, 2019 12:41
Make transcripts from YouTube captions
"""
MIT License
Copyright (c) 2019 Zev Averbach
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is