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
import os
import subprocess
from xklb.mediafiles import process_image
from xklb.utils import objects, web
COMICS = [
{
"title": "#1: Training Day",
"writer": "Ben Paddon",
"artist": "JjAR",
import argparse
import shutil
import textwrap
from itertools import zip_longest
TERMINAL_SIZE = shutil.get_terminal_size(fallback=(80, 60))
def format_two_columns(text1, text2, width1=30, width2=70, left_gutter=2, middle_gutter=2, right_gutter=3):
@chapmanjacobd
chapmanjacobd / titles.nd.js
Created May 6, 2024 15:06
Copy all titles from reddit page
Array.from(document.querySelectorAll('.title')).map(e => e.innerText).join('\n');

Have you ever wanted to do:

SELECT * FROM www.google.com

With BigQuery you kind of can. But have you ever wanted to do:

SELECT * FROM www.wikipedia.com

With Wikidata Query Service you kind of can (semantic web!, RDF!?, https://www.w3.org/wiki/SparqlImplementations).

class HtmlList:
def __init__(self):
self.tree = []
self.xpath = []
def resolve_parents(self, el) -> list:
if el.parent is None:
return self.xpath
else:
import argparse, re, webbrowser
from xklb.utils import web
def search_art(term):
search_url = f"https://artsandculture.google.com/search?q={term.replace(' ', '+')}"
response = web.requests_session().get(search_url)
if response.status_code == 200:
@chapmanjacobd
chapmanjacobd / eda sqlite example
Created March 24, 2024 16:22
lb eda temp.db -L inf
$ lb eda temp.db -L inf
## temp.db:playlists
### Shape
(1, 8)
### Sample of rows
| | id | time_modified | time_deleted | extractor_config | extractor_key | path | time_created | hours_update_delay |
def cover_scan(media_duration, scan_percentage):
num_scans = max(2, int(math.log(media_duration) * (scan_percentage / 10)))
scan_duration_total = max(1, media_duration * (scan_percentage / 100))
scan_duration = max(1, int(scan_duration_total / num_scans))
scan_interval = media_duration / num_scans
scans = sorted(set(int(scan * scan_interval) for scan in range(num_scans)))
if scans[-1] < media_duration - (scan_duration * 2):
scans.append(math.floor(media_duration - scan_duration))
def get_file_part(file_path, specifier):
size = file_path.stat().st_size
if specifier.isdigit():
specifier = int(specifier)
if specifier > 0:
with file_path.open('rb') as file:
return file.read(specifier)
else:
@chapmanjacobd
chapmanjacobd / .bashrc
Created April 23, 2020 03:28
tmux start on login .bashrc
if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
exec $(tmux a -t base || tmux new -s base)
fi