Skip to content

Instantly share code, notes, and snippets.

View Lucretiel's full-sized avatar

Nathan West Lucretiel

View GitHub Profile
@Lucretiel
Lucretiel / lisplusplus.cpp
Created October 19, 2021 23:27
Demo of lisp implemented by overloading the comma operator
#include "liscpp.h"
using namespace std;
int main()
{
ReadEvalPrint(
(Let,
tok(fold), (Lambda, tok(F), tok(I), tok(L),
@Lucretiel
Lucretiel / one-billion-line-challenge.rs
Created January 3, 2024 05:34
My solution to the 1 billion row challenge https://github.com/gunnarmorling/1brc
#![feature(slice_split_once)]
use std::{
cmp::{max, min},
collections::hash_map::Entry,
env::args_os,
fs::File,
io::{stdout, Write as _},
path::Path,
};
@Lucretiel
Lucretiel / parser.rs
Created November 24, 2021 00:12
An example nom parser for reddit
use nom::{
branch::alt,
character::complete::{alpha1, char, digit1, multispace1},
combinator::eof,
IResult, Parser,
};
use nom_supreme::{error::ErrorTree, multi::collect_separated_terminated, ParserExt};
#[derive(Debug, Clone)]
struct Structure<'a> {
from tkinter import *
import asyncio
from functools import wraps
import websockets
def runloop(func):
'''
This decorator converts a coroutine into a function which, when called,
runs the underlying coroutine to completion in the asyncio event loop.
'''
@Lucretiel
Lucretiel / joint.rs
Last active May 23, 2022 18:56
A paired smart pointer. The value owned by a pair of Joint objects is dropped as soon as *either* of the Joints are dropped
use std::{
marker::PhantomData,
mem::MaybeUninit,
ops::Deref,
process::abort,
ptr::NonNull,
sync::atomic::{AtomicU32, Ordering},
};
const MAX_REFCOUNT: u32 = i32::MAX as u32;
@Lucretiel
Lucretiel / depth_limiter.rs
Created April 29, 2022 19:13
serde deserializer adapter that limits recursion depth
pub mod sort;
use serde::de;
#[derive(Debug, Clone, Copy)]
pub struct DepthLimiter<T> {
depth: usize,
inner: T,
}
@Lucretiel
Lucretiel / ti4-parameters.json
Last active April 23, 2022 14:07
My map balance parameters for the TI4 map lab
[
{
"title": "Nathan's",
"data": {
"BASE_PLANET_MOD": 1,
"RESOURCES_MULTIPLIER": 3,
"INFLUENCE_MULTIPLIER": 2,
"TECH_MOD": 5,
"TECH_PROPULSION_MOD": 0,
"TECH_WARFARE_MOD": 0,
@Lucretiel
Lucretiel / switch.py
Last active April 15, 2022 15:40
A switch statement in python
from contextlib import contextmanager
class SwitchError(RuntimeError):
pass
@contextmanager
def switch(switch_value, *, ignore_nomatch=True):
blocks = {}
blocks.default = None
@Lucretiel
Lucretiel / raw_unsound.rs
Created April 14, 2022 02:56
demonstration of a soundness flaw in rmp_serde
use rmp_serde::Raw;
use serde::{ser, Serialize};
use thiserror::Error;
/// Serializer that serializes strings as a list of char
struct CharListSerializer {
output: Vec<char>,
}
#[derive(Debug, Error)]