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 / 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 / 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 / subframe_callback.as
Created January 21, 2020 03:44
Sample script using the subframe callback API.
class script : callback_base {
scene@ g;
array<dustman@> players;
script() {
@g = get_scene();
}
void step(int num_entities) {
int nc = num_cameras();
@msg555
msg555 / 16.cpp
Created December 17, 2019 04:04
16 dumb
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int mexp(int v, int e, int MOD) {
int ret = 1;
if (e == 0) return ret;
for(int i = 31 - __builtin_clz(e); i >= 0; i--) {
@msg555
msg555 / 10-integral.cpp
Created December 11, 2019 21:52
Float free solution to Advent Day 10
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
@msg555
msg555 / intcode.py
Last active December 8, 2019 07:46
Solution to day 7
import abc
import asyncio
import itertools
import sys
class Instruction(metaclass=abc.ABCMeta):
PARAMS = 0
def __init__(self, comp, offset, mode):