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
@chapmanjacobd
chapmanjacobd / oops.txt
Last active August 7, 2024 15:46
fixing /etc/security/limits.conf without rebooting
sudoedit /etc/security/limits.conf
# 9223372036854775807 LOL ulimit -n unlimited ?! the max might be 1048576 or 1073741816 but you should just leave this file blank unless you have multiple users that access the system
oops...
sudo: pam_open_session: Permission denied
sudo: policy plugin failed session initialization
Segmentation fault (core dumped)
... terminated by signal SIGSEGV (Address boundary error)
from fractions import Fraction
def f(y, z):
return 108 - (815 - 1500 / z) / y
# Initialize exact values using Fraction for exact arithmetic
xExact = {0: Fraction(4), 1: Fraction(17, 4)}
# Initialize floating point values
xFloat = {0: 4.0, 1: 4.25}
import os
from pathlib import Path
def rglob_no_xdev(path, pattern):
start_dev = os.stat(path).st_dev
def _rglob_no_xdev(path, pattern, start_dev):
for p in path.glob(pattern):
if p.is_dir():
try:
@chapmanjacobd
chapmanjacobd / plot_oomstat.py
Last active July 13, 2024 06:23
plot /proc/pressure/memory
# https://github.com/rfjakob/earlyoom/blob/c759f1bef2b50d0e0b249bff650e730655c98c0e/contrib/oomstat/overload.txt
import matplotlib.pyplot as plt
import pandas as pd
from xklb.utils import processes
df = pd.read_csv(StringIO(processes.cmd('cb').stdout.replace('|',' ')), delim_whitespace=True)
df.set_index('Time', inplace=True)
df = df.apply(pd.to_numeric)
@chapmanjacobd
chapmanjacobd / mock_stdin.py
Created May 17, 2024 15:03
restore stdin on error for pytest pdb
import sys
import pytest
from io import StringIO
class MockStdin:
def __init__(self, input_text):
self.input_text = input_text
self.original_stdin = None
@chapmanjacobd
chapmanjacobd / example_json.py
Created May 10, 2024 06:31
Filter JSON based on example
import argparse
import json
import sys
from typing import Any, Dict
import ijson
import ijson.common
from xklb.utils import argparse_utils
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).