Skip to content

Instantly share code, notes, and snippets.

# https://codegolf.stackexchange.com/questions/59670/the-drunken-bishop
def h(f):
# Alias 17 because it gets used enough times for this to save bytes
w = 17
h = 9
# Input parsing
s = [f"{int(g,16)>>s&3:02b}" for g in f.split(":") for s in (0, 2, 4, 6)]
@parsa
parsa / boost_mp_cppint_fib.cpp
Created November 16, 2022 17:45
Fibonacci using boost::multiprecision::cpp_int
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>
int main() {
boost::multiprecision::cpp_int n1 = 0, n2 = 1;
for (long i = 1; i <= 1000000; ++i) {
n1 = std::exchange(n2, n1 + n2);
}
std::cout << n2;
}
@parsa
parsa / multiprocessing.pool-with-queue.py
Created November 14, 2022 15:21
Python - Sharing a queue between multiprocessing.Pool tasks
import multiprocessing
import subprocess
import tqdm
def work(args):
def workimpl(task_id, core_ids_queue):
core_id = core_ids_queue.get()
tqdm.tqdm.write(
\Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr)

$$ \Biggl(\biggl(\Bigl(\bigl((x)\bigr)\Bigr)\biggr)\Biggr) $$

@parsa
parsa / CMakeLists.txt
Last active March 22, 2023 14:29
Stop and start `perf` measurements with a named pipe
cmake_minimum_required(VERSION "3.23")
# C project
project(xenodochial_sinoussi C)
add_executable(prog prog.c)
import os
import subprocess
def lmod(command: str, *args: str, verbose: bool = False, dry_run: bool = False):
"""
Basic wrapper for lmod commands.
Based on https://github.com/TACC/Lmod/blob/master/init/env_modules_python.py.in
Parameters
@parsa
parsa / hpx_reverse.cpp
Created June 10, 2020 02:46 — forked from BillyONeal/hpx_reverse.cpp
HPX reverse comparative
#include <hpx/hpx.hpp>
#include <hpx/hpx_init.hpp>
#include <hpx/parallel/algorithms/reverse.hpp>
#include <algorithm>
#include <execution>
#include <functional>
#include <random>
#include <vector>
#include "stopwatch.hpp"

HPX performance counter line filter

^/[^{]+\{[^}]+\}/([^,]+,)*[^,]+$

Matches:

/objectname{full_instancename}/countername@parameters[,whatever[,whatever]...]
curl -sSL https://get.docker.com | sh
# SLURM {{{ #
function idev() {
local nodes="1"
if [[ "$(sinfo -h -o "%P")" =~ .*^$1$.* ]]; then
local partition="$1"
shift
fi
if [[ "$1" =~ [0-9]+ ]]; then
nodes="$1"
shift