Skip to content

Instantly share code, notes, and snippets.

View chapmanjacobd's full-sized avatar
🥅
goal_net

Jacob Chapman chapmanjacobd

🥅
goal_net
View GitHub Profile
def mpv_enrich(args, media) -> List[Dict]:
for m in media:
md5 = path_to_mpv_watchlater_md5(m["path"])
metadata_path = Path(args.watch_later_directory, md5)
if metadata_path.exists():
m["time_partial_first"] = int(metadata_path.stat().st_ctime)
m["time_partial_last"] = int(metadata_path.stat().st_mtime)
else:
m["time_partial_first"] = 0
def calculate_sparseness(stat) -> int:
if stat.st_size == 0:
sparseness = 0
else:
blocks_allocated = stat.st_blocks * 512
sparseness = blocks_allocated / stat.st_size
return sparseness
class DictHandler(logging.Handler):
def __init__(self, log_dict):
super().__init__()
self.log_dict = log_dict
def emit(self, record):
log_entry = self.format(record)
self.log_dict.setdefault(record.levelname, []).append(log_entry)
def load_spacy_model(model=None):
try:
import spacy
except ModuleNotFoundError:
log.error("Install spaCy and sklearn to use:")
log.error("pip install spacy sklearn")
log.error("python -m spacy download en_core_web_sm")
sys.exit(1)
if model:
@chapmanjacobd
chapmanjacobd / freed_up_one_terabyte.md
Last active June 11, 2023 11:03
How I freed up one TiB of space

How I freed up one TiB of space

I didn't realize just how much space those 24 Hour YouTube tracks take up. After hearing the same song on repeat I decided to check:

$ pip install xklb
$ lb fsadd --audio ~/lb/audio.db /mnt/d/81_New_Music/ /mnt/d/82_Audiobooks/
$ lb listen ~/lb/audio.db /81_New_Music/ --duration +3hr -p a
╒═══════════╤═════════╤═══════════════════════════════════════════╤═══════════════════════════╤══════════════════════════════════════════╤════════╤════════════╕
│ path      │   count │ duration                                  │ avg_duration              │ cadence_adj_duration                     │ size   │ avg_size   │

╞═══════════╪═════════╪═══════════════════════════════════════════╪═══════════════════════════╪══════════════════════════════════════════╪════════╪════════════╡

-- v3
from db import con, fetchall_dict, singleColumnToList
def run_query(sql):
cur = con.cursor()
cur.execute(sql)
con.commit()
CREATE TABLE transport_intercity_guess_bus AS
WITH bus AS (
SELECT
cf.id city_from,
ct.id city_to,
0 AS transfers,
avg(price_avg) as price,
avg(distance_avg) as distance,
null transfer_city
from
@chapmanjacobd
chapmanjacobd / pylint-pyproject.toml
Created April 24, 2023 10:15
pylint pyproject.toml
[tool.pylint.main]
fail-under = 8.0
ignore = ["input"]
ignored-modules = ["pandas", "numpy"]
limit-inference-results = 100
persistent = true
suggestion-mode = true
[tool.pylint.basic]
argument-naming-style = "snake_case"
sqlite3 artist_similarity.db 'alter table artists add column artist_name text'
---
attach 'artist_similarity.db' AS sim;
attach 'track_metadata.db' AS tr;
UPDATE
sim.artists SET artist_name = (
SELECT
artist_name
FROM
@chapmanjacobd
chapmanjacobd / gdal_block_reading.py
Last active March 9, 2023 04:27
Actual speed impact of reading mismatched blocks
import math
import osgeo.gdal as gdal
import timeit
file_path = "1677269839.tif"
ds = gdal.Open(file_path)
file_block_size = ds.GetRasterBand(1).GetBlockSize()
xoff = 0