Skip to content

Instantly share code, notes, and snippets.

View AlexRiina's full-sized avatar

Alex Riina AlexRiina

View GitHub Profile
@AlexRiina
AlexRiina / denest_imports.py
Last active March 20, 2022 21:27
Remove layers from deep imports where possible
"""
Search for imports that are not at the top-level and replace them with
top-level imports.
from x.y import Z -> from x import Z
NOTE: doesn't handle comments or `import x as y`
"""
import argparse
@AlexRiina
AlexRiina / deoptional.py
Last active August 23, 2020 23:02
remove Optional[] annotation wrappers where redundant
"""
Optional[] is implied in arguments when the default value is None. Leaving it
out is a matter of personal preference and I prefer to leave it out in favor of
shorter lines with not obvious behavior.
This script removes unnecessary Optional declarations in arguments.
WARNING: this updates files in-place.
"""
@AlexRiina
AlexRiina / anki_similarity.py
Created July 10, 2020 21:37
Find duplicate notes in Anki
"""
Text clustering of Anki cards to find duplicated concepts. Prints handful of notes and then a list of similar notes.
```
pip install anki_sqlalchemy bs4 sklearn
cp ${ANKI_DATABASE:?replace me} backup.db
python anki_similarity.py
```
"""
@AlexRiina
AlexRiina / hospitalizations_and_viral_rna.csv
Last active May 27, 2020 05:07
sewer SARS-CoV-2 RNA vs hospital admissions
date viral_rna hospitalizations
19/03/2020 5 8
20/03/2020 5 10
21/03/2020 25 3
22/03/2020 0 8
23/03/2020 50 10
24/03/2020 30 12
25/03/2020 80 8
26/03/2020 80 10
27/03/2020 85 17
@AlexRiina
AlexRiina / codemapper.py
Last active February 3, 2020 18:51
Utility for grouping files by codeower and generating commands
"""
Utility for grouping files by codeower and generating commands
"""
import argparse
import re
import shlex
from collections import defaultdict
from glob import fnmatch
from typing import DefaultDict, FrozenSet, Iterator, Optional, Set, Tuple
@AlexRiina
AlexRiina / noqaer.py
Last active May 11, 2023 00:33
automatically ignore lines from flake8
"""
Add `# noqa: FXXX` comments to all lines with violations from flake8
"""
# MIT License
#
# Copyright (c) 2022 Alex Riina
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@AlexRiina
AlexRiina / overlay-exif.py
Last active February 3, 2019 20:31
Overlay photo speed, aperture, and ISO
"""
Add legend with exposure speed, aperture, and ISO to top left of jpeg photo exif data.
Copies original exif data into output file.
Requires Python3.6, and some version of Pillow
"""
import argparse
from PIL import Image, ImageDraw, ImageColor, ImageFont
from PIL.ExifTags import TAGS, GPSTAGS
@AlexRiina
AlexRiina / publish.sh
Last active December 1, 2017 15:06
Publish Jekyll posts using simple git workflow
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Move jekyll draft to post, timestamp it, and start to commit it
# Useage:
# $ ./publish.sh _draft/cool-article.markdown
# moves the draft to _posts/2017-12-01-cool-article.markdown
# inserts the published date into the "front matter"
@AlexRiina
AlexRiina / walmart_mvp.html
Created November 3, 2017 19:33
Walmart BuyNow MVP with Javascript API
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.slim.js"></script>
</head>
<body>
<div class="walmart-buy-now" data-publisherid="PD0Em23B4ME" data-item-walmartid="45698070|2,631|1" data-color="orange" data-size="standard"></div>
@AlexRiina
AlexRiina / deeplink_buy_now.html
Last active November 6, 2017 16:34
Walmart Deeplink Api