Skip to content

Instantly share code, notes, and snippets.

View shreve's full-sized avatar

Violet Shreve shreve

View GitHub Profile
@shreve
shreve / boost.js
Last active June 22, 2023 15:26
Twitter Trending Topics Cleaner
const blocklist = ["Matt Walsh", "Musk", "Joe Rogan", "Biden", "Rowling"];
let cleanseListener = null;
const cleanseTopics = () => {
let topics = document.querySelectorAll("[data-testid='trend']");
if (topics.length == 0) return;
topics = Array.prototype.slice.apply(topics);
badTopics = topics.filter((el) => {
@shreve
shreve / lazy.py
Created June 6, 2023 21:36
Lazy evaluation wrapper for python
from typing import Callable, Generic, TypeVar, Any
Type = TypeVar("Type")
class Lazy(Generic[Type]):
"""
Define a lazily-evaluated value. The function will only be called once, and the
container will invisibly act like the value.
"""
@shreve
shreve / main.py
Created September 21, 2022 18:18
pydantic settings customized sources
import os
from pydantic import BaseSettings
os.environ["VALUE"] = "2"
def record_call(func):
def wrapper(*args, **kwargs):
print(f"Calling {func.__class__.__name__}")
result = func(*args, **kwargs)
@shreve
shreve / collect_oids.sh
Last active September 9, 2022 18:20
GitHub LFS Scan
#!/usr/bin/env bash
# Collect the list of object IDs and their sizes from a single repo
git lfs ls-files --all -d | awk 'NR % 7 == 2 {size=$2} NR % 7 == 5 {oid=$3 } NR % 7 == 0 {print oid " " size}' > files.txt
@shreve
shreve / stdout
Created August 9, 2022 16:29
A simple demo of the ordering of try/except/else/finally in python
testing dont_raise
try
else
finally
testing raise_known
try
except KnownException
finally
@shreve
shreve / dolphin.py
Created August 9, 2022 04:11
Read and modify your FlipperZero dolphin's state
"""
Dolphin.py
Access your dolphin's state.
"""
import sys
from struct import Struct
apps = [
@shreve
shreve / docker_layer_sizes.py
Last active July 14, 2022 19:48
Docker layer size report
"""
Docker layer size report
python docker_layer_sizes.py <image>
Returns the size of each layer of the image and the command that created it.
This is a decorative layer on top of the docker history command.
"""
@shreve
shreve / e.py
Last active December 18, 2021 18:48
Computationally generate e
# Code sample of the following tweet:
# https://twitter.com/fermatslibrary/status/1449027186267197463
import random
import math
def compute_average(d):
return sum([num * count for (num, count) in d.items()]) / sum(d.values())
@shreve
shreve / tp.md
Last active March 30, 2024 04:47
TP-Link Router Config Decrypt

TP-Link Router Config

Update 2021-04-29: This may still work for you if you've got an old TP-Link router, but this is not maintained and doesn't work with newer models. If you've got a newer router, other projects like tpconf_bin_xml will likely work better for you.

TP-Link allows you to backup and restore your router's config file. For some reason, they decided to encrypt these backups so you cannot modify them. I think this is dumb. This script lets you decrypt and re-encrypt your config files so you can modify them as you see fit.

I use this to modify my reserved addresses list because editing them through the web interface is terribly slow and cumbersome.

  1. Go to the router and download the config file from the "Backup & Restore" section of "System Tools".
  2. Run ruby tp.rb config.bin
@shreve
shreve / twitter.js
Created June 14, 2019 00:45
Easy Tweet Delete
let del = () => {
let links = [].slice.apply(document.querySelectorAll('.js-actionDelete button'));
let link = links.filter((el) => { return el.offsetHeight > 0 })[0];
console.log(link);
if (link) { link.click(); }
let el = document.querySelector('.delete-action');
if (el.offsetHeight > 0) { el.click(); }
}
setInterval(del, 300);