Skip to content

Instantly share code, notes, and snippets.

View barrucadu's full-sized avatar

Michael Walker barrucadu

View GitHub Profile
# pyrite: strict
import typing
import random
T = typing.TypeVar("T")
def weighted_choice(freqdict: dict[T, int]) -> T:
items = freqdict.items()

Your good friend Jackson Elias calls for your help with a telegram scarce on details. Something about the ill-fated Carlyle Expedition of 1920, where everyone ended up dead. He said he's found something. You arrive at his hotel room and knock on the door, but get no response. The door is ajar. You push it open and see a man in a dark suit standing there.

"I'm here to help you," says the stranger. "You're not going to believe what I've found."

He leads you into an empty office and closes the door behind him.

You say "Where's Jackson Elias?"

"Jackson? What happened to him?"

data ThreadId = ThreadId
{ realThreadId :: Int
, exceptionVariable :: TVar (Maybe SomeException)
, canBeThrownTo :: TVar Bool
}
-- when a thread is created: canBeThrownTo depends on the masking state (True for Unmasked, False otherwise)
-- when a thread is killed: canBeThrownTo is True
---
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
class IsSubtypeOf a b where
to :: a -> b
from :: b -> Maybe a
instance IsSubtypeOf Int Int where
to = id
from = Just
@barrucadu
barrucadu / isogram.c
Created March 5, 2020 12:50
There are two different definitions of "isogram": this uses the definition "there are no duplicate characters"
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare_chars(const void* ap, const void *bp) {
char a = *((char*) ap);
char b = *((char*) bp);
@barrucadu
barrucadu / more-jmp.c
Last active February 24, 2020 16:39
clang jmp-cflow.c -Weverything -Wno-shadow -Wno-unused-variable -Wno-missing-noreturn -Wno-reserved-id-macro -Wno-unused-macros -Werror
#include <setjmp.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define BEGIN_BLOCK \
{ \
volatile uint8_t orig_exc_i = exc_i; \
volatile uint8_t exc_i = orig_exc_i + 1; \
#include <setjmp.h>
#include <stdio.h>
int main(void) {
jmp_buf buf;
int a, b;
switch(setjmp(buf)) {
case 0:
case 1:
/// Check if two items are in the same equivalence class.
fn in_class(rel: BTreeMap<EUFTerm, BTreeSet<EUFTerm>>, left: &EUFTerm, right: &EUFTerm) -> bool {
let mut seen = BTreeSet::new();
let mut todo = vec![left];
let empty_set = BTreeSet::new();
while let Some(next) = todo.pop() {
for candidate in rel.get(next).unwrap_or(&empty_set).difference(&seen) {
if *candidate == *right {
return true;
Definitions:
```
f(n) = O(g(n)) <==> \exists x_0 \in R, m \in R+, \forall x >= x_0, 0 < g(x) \land |f(x)| <= m * g(x)
```
Let `a(n) = O(b(n))`
Let `c(n) = O(d(n))`
We have:
I've got three nodes in an AWS VPC: a jumpbox accessible by external SSH (configuration file: jumpbox.nix), a
k8s master node (configuration file: k8s-master.nix) and a k8s worker node (configuration file: k8s-slave.nix)
in a private subnet (with all traffic allowed between them).
All these .nix files, and the deploy.sh file, are copied to ~/nixos on the jumpbox and then deploy.sh run to set
everything up.
DNS is set up so that these domains resolve to the right machines:
- k8s-master.govuk-k8s.test
- k8s-slave.govuk-k8s.test