Skip to content

Instantly share code, notes, and snippets.

@nightuser
nightuser / optional_deps.py
Created April 14, 2022 16:37
Gentoo: list optional dependencies for installed packages
#!/usr/bin/env python3
import re
import portage
import shlex
optfeature_re = re.compile(r'optfeature\s+(.*)$')
packages = portage.db[portage.root]['vartree'].dbapi.cpv_all()
@nightuser
nightuser / AdjustableClock.java
Last active November 28, 2023 11:36
Java Adjustable Clock
package fun.nightuser;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
public class AdjustableClock extends Clock {
private Clock fixedClock;
@nightuser
nightuser / Makefile
Last active November 17, 2023 16:51
Simple C++ Makefile
BIN := main
CXXFLAGS += -Wall -Wextra -std=c++20
CPPFLAGS += -MMD
SRCS := $(wildcard *.cc)
OBJS := $(SRCS:.cc=.o)
DEPS := $(SRCS:.cc=.d)
LINK.o = $(CXX) $(LDFLAGS) $(TARGET_ARCH)
all: $(BIN)
@nightuser
nightuser / aoc23_day13.py
Created December 13, 2023 14:24
AoC 2023 Day 13
import sys
from typing import Optional
def dist(xs: list[str], i: int, k: int) -> int:
return sum(c1 != c2 for c1, c2 in zip(xs[i + k], xs[i - k - 1], strict=True))
def weak_palindromes(xs: list[str]) -> list[tuple[int, Optional[int]]]:
left = 0