Skip to content

Instantly share code, notes, and snippets.

@tttardigrado
tttardigrado / pll.hs
Last active November 24, 2024 08:42
P'' implementation in under 30 lines of Haskell
data P = R | L | Seq P P | Loop P
data Tape = Tape [Int] Int [Int]
empty :: Tape
empty = Tape (repeat 0) 0 (repeat 0)
left :: Tape -> Tape
left (Tape (l:ls) v rs) = Tape ls l (v:rs)
@AndrasKovacs
AndrasKovacs / TwoStageRegion.md
Last active March 24, 2025 14:55
Lightweight region memory management in a two-stage language
@brendanzab
brendanzab / open-interperters.ml
Last active December 31, 2024 14:41
Open interpreters using polymorphic variants and extensible variants.
(** This is a demonstration of implementing interpreters in an extensible way
that offers a partial solution to the expression problem. The idea is that
the language can be extended with more features after the fact, without
altering previous definitions. It also has the benefit of grouping the
related extensions to the syntax and semantic domains together with the
relevant evaluation rules in a per-feature way.
This approach used is similar to the one described by Matthias Blume in
{{:https://www.microsoft.com/en-us/research/video/records-sums-cases-and-exceptions-row-polymorphism-at-work/}
Records, sums, cases, and exceptions: Row-polymorphism at work}.
@FreyaHolmer
FreyaHolmer / GpuPrinter.cginc
Last active March 16, 2025 05:51
A unity shader .cginc to draw numbers in the fragment shader - see the first comment below for example usage!
///////////////////////////////////////////////////////////////////////////////
// ABOUT: A unity Shader .cginc to draw numbers in the fragment shader
// AUTHOR: Freya Holmér
// LICENSE: Use for whatever, commercial or otherwise!
// Don't hold me liable for issues though
// But pls credit me if it works super well <3
// LIMITATIONS: There's some precision loss beyond 3 decimal places
// CONTRIBUTORS: yes please! if you know a more precise way to get
// decimal digits then pls lemme know!
// GetDecimalSymbolAt() could use some more love/precision
@darvil82
darvil82 / british_python.py
Created July 25, 2022 18:59
British python
class BritishNaming(type):
def __new__(mcs, *args):
cls = super().__new__(mcs, *args)
cls.__init__ = cls.__innit__
return cls
class MyBritishClass(metaclass=BritishNaming):
def __innit__(self):
print("I am british now ig")
@quackbarc
quackbarc / fizzbuzz_regex.md
Last active September 4, 2024 19:14
a fizzbuzz pattern made with pure regex
\b(?:(?<fizzbuzz>(?:(?:[369]|[258][0369]*[147]|(?:[147]|[258][0369]*[258])(?:[0369]|[147][0369]*[258])*(?:[28]|[147][0369]*[147]))*(?:0|(?:[147]|[258][0369]*[258])(?:[0369]|[147][0369]*[258])*5))+)|(?<buzz>\d*[05])|(?<fizz>(?:[0369]|[258][0369]*[147]|(?:[147]|[258][0369]*[258])(?:[0369]|[147][0369]*[258])*(?:[258]|[147][0369]*[147]))+))\b

insanity, as i'd like to call it. although it isn't fizzbuzz per se, it's the best you can get with regex. here's a regexr link to it with sample text.

this matches a number (within word boundaries) if it falls under any of the three groups:

  • fizzbuzz, which picks up numbers divisible by both 3 and 5, i.e. 15;
  • buzz, which picks up numbers divisible by 5; and
  • fizz, which picks up numbers divisible by 3.
@jemmanuel
jemmanuel / reallocation.md
Created April 10, 2020 14:26
Optimal memory reallocation and the golden ratio

This is based on a neat little post that I saw on Simon Frankau‘s blog that I thought I’d provide a few more details on, as well as bringing it to a wider audience. Some higher-level data structures in object-oriented programming languages have dynamic memory allocation. This is used to create objects (usually things that behave like lists) that can grow and shrink as the program executes. When initializing a regular array in C or Java, you have to specify the size of the array on creation, for example with

int myArray[] = new int[10];
@pedrominicz
pedrominicz / Hylo.hs
Created November 15, 2019 15:44
Catamorphisms, Anamorphisms, and Hylomorphisms.
{-# LANGUAGE UndecidableInstances #-}
module Hylo where
-- An attempt to derive a hylomorphism from the type signature (at the time of
-- writing I don't recall ever seeing the implementation of one).
type Algebra f a = f a -> a
type Coalgebra f a = a -> f a
@pedrominicz
pedrominicz / Everything.md
Last active May 28, 2024 21:56
Every Gist I've written.

The originality of these Gists varies drastically. Most are inspired by the work of others, in that case, all merit goes to the original authors. I have linked everything used as reference material on the Gists themselves.

Haskell

According to all known laws of aviation, there is no way a bee should be able to fly.
Its wings are too small to get its fat little body off the ground.
The bee, of course, flies anyway because bees don't care what humans think is impossible.
Yellow, black. Yellow, black. Yellow, black. Yellow, black.
Ooh, black and yellow!
Let's shake it up a little.
Barry! Breakfast is ready!
Coming!
Hang on a second.
Hello?