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 / re_sparse.fish
Created September 7, 2024 12:41
re-sparse hydrated files
function is_sparse_file
set actual_size (du --block-size=1 "$argv" | awk '{print $1}')
set apparent_size (du --block-size=1 --apparent-size "$argv" | awk '{print $1}')
if test $actual_size -eq $apparent_size
return 1
else
return 0
end
end
@chapmanjacobd
chapmanjacobd / btrfs_metadata_corruption.md
Created September 4, 2024 08:29
when lightning strikes
  • reboot
  • sudo btrfs rescue zero-log /dev/sdf1
  • sudo btrfs check -s 1 -b /dev/sdf1
  • sudo mount -o ro,rescue=all /mnt/d1
@chapmanjacobd
chapmanjacobd / not.words.txt
Created September 3, 2024 12:14
13,353 unusual words that are not in /usr/share/dict/linux.words
aaliyah
abbatis
abbrevs
abditos
abdominousness
abductee
abductees
abductive
aber
abest
// ==UserScript==
// @name Hide Seen Rows
// @namespace http://tampermonkey.net/
// @version 0.31
// @description Remember and hide unique rows based on URL
// @author Jacob Chapman
// @match *://*/*
// @grant none
// ==/UserScript==
# tag target commits as demo-start, demo-end
# move to the start of your presentration with `git checkout demo-start`
# use to `git next`, `git prev` to jump between "slides"
git config --global alias.next '!git checkout `git rev-list HEAD..demo-end | tail -1`'
git config --global alias.prev 'checkout HEAD^'
@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