Skip to content

Instantly share code, notes, and snippets.

View abdelq's full-sized avatar

Abdelhakim Qbaich abdelq

  • 05:00 (UTC -04:00)
View GitHub Profile
@abdelq
abdelq / euler_60.zig
Created December 15, 2023 23:43
Project Euler: 60 Prime Pair Sets
const std = @import("std");
const ArenaAllocator = std.heap.ArenaAllocator;
const ArrayHashMap = std.AutoArrayHashMap;
const ArrayList = std.ArrayList;
const WriteError = std.os.WriteError;
const is_prime = @import("test.zig").is_prime;
const seg_sieve = @import("sieve.zig").seg_sieve;
// Could use a better name...
from base64 import b32encode
from hashlib import sha3_256
TLD = '.onion'
def calculate_checksum(pubkey: bytes, version: bytes = b'\x03') -> bytes:
constant = b'.onion checksum'
return sha3_256(constant + pubkey + version).digest()[:2]
def generate_onion_address(pubkey: bytes, version: bytes = b'\x03') -> str:
@abdelq
abdelq / babylon.scm
Created May 29, 2022 22:29
Old Guix config for a ThinkPad
(use-modules (gnu) (guix packages) (srfi srfi-1))
(use-system-modules locale)
(use-service-modules avahi cups desktop linux networking pm xorg)
(use-package-modules android gnome linux radio shells wm)
(define %my-udev-rules
(let ((unauthorize
(lambda (subsystem product)
(string-append
"SUBSYSTEM==\"" (symbol->string subsystem) "\", "
@abdelq
abdelq / credit.py
Last active December 25, 2023 23:46
Convert RBC's credit statements to CSV
#!/usr/bin/env python
import re
from itertools import chain
from math import isclose
from dateparser import parse as dateparse
def parse_date(*args, **kwargs):
@abdelq
abdelq / xicor.py
Created December 29, 2021 01:34
Chatterjee's rank correlation
import numpy as np
import numpy.typing as npt
# TODO https://arxiv.org/abs/2108.06828
def xicor(x: npt.ArrayLike, y: npt.ArrayLike) -> np.float_:
x, y = np.asanyarray(x), np.asanyarray(y)
assert x.ndim == 1 and y.ndim == 1, "arrays must be one-dimensional"
assert len(x) == len(y), "arrays must have the same length"
# XXX Checking if every value of y is the same (NaN)?
@abdelq
abdelq / icbc.sh
Last active November 25, 2021 03:35
#!/bin/sh
LAST_NAME=
KEYWORD=
LICENCE_NUM=
POS_ID=
EXAM_TYPE=
EXAM_DATE=
def levenshtein_distance(s1: str, s2: str) -> int:
if s1 == s2:
return 0
if not s1:
return len(s2)
if not s2:
return len(s1)
prev, curr = None, range(len(s2) + 1)
@abdelq
abdelq / bruker.py
Last active November 8, 2022 22:05
Exporting OPUS libraries to Zarr storage
#!/usr/bin/env python3
import logging
import re
from collections import defaultdict
from io import FileIO
from itertools import count
from pathlib import Path
from typing import Callable
@abdelq
abdelq / tarjan.js
Last active July 11, 2020 19:29
Tarjan's strongly connected components algorithm
function* tarjan(graph) {
let index = 0;
const stack = [];
function* strongConnect(v) {
v.index = index, v.lowlink = index, v.onStack = true;
index += 1;
stack.push(v);
for (let w of v.successors.map(i => graph[i])) {
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.PriorityQueue;
/**
* @author Abdelhakim Qbaich
*/