Skip to content

Instantly share code, notes, and snippets.

@msg555
msg555 / day2.tf
Created December 4, 2023 09:18
AdventAsCode Day 2
data "local_file" "input" {
filename = "${path.module}/input.txt"
}
locals {
games = [
for line in split("\n", chomp(data.local_file.input.content)) :
{
game = tonumber(substr(split(":", line)[0], 5, -1))
observations = [
@msg555
msg555 / day1.tf
Created December 4, 2023 08:43
AdventAsInfrastructure
data "local_file" "input" {
filename = "${path.module}/input.txt"
}
locals {
reps = {
one = "1"
two = "2"
three = "3"
four = "4"
@msg555
msg555 / 3dhull.cpp
Last active April 1, 2023 17:39
3D Convex Hull
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cassert>
using namespace std;
@msg555
msg555 / replay.php
Created February 13, 2021 21:13
Replay read/write routines for dustkid
<?php
function _substr($data, $pos, $len) {
if (0 <= $pos && $pos + $len <= strlen($data) && $pos <= $pos + $len) {
return substr($data, $pos, $len);
}
return null;
}
function _unpack_byte($data, $pos) {
$str = _substr($data, $pos, 1);
@msg555
msg555 / less_unfair_scheduling.cpp
Created February 21, 2022 02:44
Analog of https://gist.github.com/msg555/dd491078cf10dbabbe7b1cd142644910 in C++. Still not that fair but doesn't permanently starve threads.
#include <unistd.h>
#include <sys/time.h>
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <chrono>
using namespace std;
@msg555
msg555 / unfair_queue.py
Created February 21, 2022 02:17
Example of unfair scheduling using queue.Queue in CPython
from threading import Thread, get_ident
import time
from queue import Queue
THREAD_COUNT = 10
POOL_GET_TIMEOUT = 10.0
POOL_SIZE = 2
pool = Queue()
for i in range(POOL_SIZE):
@msg555
msg555 / unfiar_scheduling.py
Created February 21, 2022 00:59
Example of unfair scheduling in CPython's condition variable implementation
from threading import Condition, Thread
import time
# This is a sample implementation of something like an object pool. It uses
# a condition variable to ensure that at most `counter` threads are allowed
# to execute at a time.
THREAD_COUNT = 10
counter = 1
cnd = Condition()
@msg555
msg555 / gist:5418199
Last active October 30, 2021 19:27
Stack Switching
#include <stdio.h>
#include <stdlib.h>
#define STACK_SIZE (1 << 26)
#define STACK_PAD 128
int rec(int n) {
return n == 0 ? 0 : rec(n - 1) + 1;
}
@msg555
msg555 / dustapi.as
Last active September 19, 2021 22:19
The DF API definitions
This has been replaced by https://dustapi.readthedocs.io/
@msg555
msg555 / suffix_linear.cpp
Created September 14, 2013 20:58
Linear time DC3 Suffix Array Construction (And driver program to solve http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2507)
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAXN 1010
int AN;