Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / use_existing_session.patch
Last active March 27, 2024 17:02
Use existing Xorg session for chrome-remote-desktop
Add an option to use the existing Xorg session with
chrome-remote-desktop.
The original idea of the patch: https://superuser.com/a/850359
--- a/chrome-remote-desktop 2024-03-27 16:03:20.518579015 +0000
+++ b/chrome-remote-desktop 2024-03-27 16:17:58.241912847 +0000
@@ -110,6 +110,8 @@
X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock"
FIRST_X_DISPLAY_NUMBER = 20
@nightuser
nightuser / main.cpp
Last active March 21, 2016 00:34
Incomplete long arithmetics
#include <algorithm>
#include <iostream>
#include <vector>
#include <csignal>
using std::cout;
using std::endl;
using vint = std::vector<int>;
int const kBase = 100;
@nightuser
nightuser / wiener.py
Created May 25, 2015 21:10
HW05: Wiener process
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import bisect
import numpy as np
from functools import total_ordering
from numpy.random import normal
from pylab import *
@nightuser
nightuser / hw04.py
Last active August 29, 2015 14:21
HW04: Convex polygon with random order
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
from functools import cmp_to_key
from pylab import *
from scipy import stats
def standard_simplex_draw_point(n):
@nightuser
nightuser / test1.py
Last active August 29, 2015 14:18
Sympy bad performance with polynomials
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
from sympy import Poly, Symbol
from scipy.signal import fftconvolve
x = Symbol('x')
k = 19937
@nightuser
nightuser / bbs_crack.py
Last active November 28, 2022 16:12
Blum-Blum-Shub
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sympy import pollard_rho
from sympy.core.numbers import igcd
from sympy.ntheory import sqrt_mod, nthroot_mod, isprime, factorint
from sympy.ntheory.modular import crt
with open('bbs.txt', 'r') as f:
xs = [int(x.rstrip()) for x in f.readlines()]