Skip to content

Instantly share code, notes, and snippets.

@sjolsen
sjolsen / fork_fd.c
Created June 29, 2024 03:42
demonstrating shared file description state across fork
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
int write_all(int fd, const void *buf, size_t count) {
const char *cbuf = (const char *)buf;
@sjolsen
sjolsen / permute_words.py
Created March 14, 2024 06:47
word permutations
import collections
import dataclasses
import sys
from typing import Iterable, Self
IGNORED_WORDS: frozenset[str] = frozenset([
'adv',
'dis',
'eds',
@sjolsen
sjolsen / callable-class.lisp
Created March 12, 2024 21:14
CLOS classes that can be constructed by calling them
(defclass callable-class (standard-class function)
()
(:metaclass sb-mop:funcallable-standard-class))
(defmethod sb-mop:validate-superclass ((class callable-class) superclass)
(or (typep superclass 'callable-class)
(typep superclass 'standard-class)))
(defmethod initialize-instance :after ((class callable-class) &rest rest &key &allow-other-keys)
(declare (ignore rest))
@sjolsen
sjolsen / unneeded.py
Created June 1, 2023 01:43
List installed packages that APT can't figure out aren't needed
import apt
import networkx as nx
def is_root(pkg: apt.package.Package) -> bool:
if not pkg.is_installed:
return False
if not pkg.is_auto_installed:
return True
if pkg.essential:
module Grammar where
open import Category.Applicative
open import Data.Char using (Char)
open import Data.List using (List)
open import Data.List.NonEmpty using (List⁺; map; foldl₁; fromList)
open import Data.Maybe using (from-just)
open import Data.Nat using (ℕ; _+_; _*_)
open import Data.String using (String; toList)
open import Data.Unit
open import Function
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import sys
from typing import FrozenSet, Iterable, Iterator, List, NamedTuple, NewType, Sequence, Set
from frozendict import frozendict
from multiset import FrozenMultiset
# Text munging
def normalize(s: str) -> str:
return ''.join(c.lower() for c in s if c.isalnum())
@sjolsen
sjolsen / use_me.rs
Created November 10, 2019 03:28
Zero-cost futures?
use futures::executor::*;
use futures::future::*;
use futures::task::*;
use futures_util::pin_mut;
use std::pin::*;
async fn use_me(i: i32) -> i32 {
i
}
#include <charconv>
#include <iostream>
#include <string>
#include <system_error>
std::string to_hex(uint64_t val) {
char buf[16];
auto [end, e] = std::to_chars(std::begin(buf), std::end(buf), val, 16);
if (e != std::errc()) {
throw std::system_error(std::make_error_code(e));
@sjolsen
sjolsen / Types2.agda
Created April 4, 2016 07:31
Enough STLC to implement single-step η-reduction
open import Level using () renaming (suc to lsuc)
open import Data.Empty
open import Data.Nat hiding (compare)
open import Data.Nat.Properties
open import Data.Product
open import Data.Sum
open import Data.Vec
open import Function
open import Relation.Nullary
open import Relation.Nullary.Negation