Skip to content

Instantly share code, notes, and snippets.

@LdBeth
LdBeth / ca.dyalog
Created February 2, 2020 09:59
APL plot code for A New Kind of Science
acc ← {⍺←1 ⋄ ((⊢⍪(⍺⍺∘,¯1↑⊢))⍣⍺)⍵}
cell ← {((⍺⍺ ⍵⍵⊢)⌺3)⍵}
code ← {⎕IO←0 ⋄ (+/⍵)⌷⌽(7⍴3)⊤⍺}
expnd ← {(,⍉↑⍺)/,¯1 0 1(+⍤0 1)⍵}
gmob ← {⍵ snap⍨(⊂L),↓⍉↑(⍺⍺ ⍵⍵ ⍵⌷⍨∘⊂¯1 0 1∘+)¨L←⍸1<⍵}
gr ← {(A rule P)(B patn P)⊣A B←⍺⊣P←2|⍵}
initi ← {⍺←1 ⋄ ,[⎕IO-0.5]A,⍺,A←⍵⍴0}
mcomp ← {((⌽⍣(B rule P))0 0 2)+(⊃A B←⍺)patn⊢P←⍵-0 2 0}
mobile ← {((⍺⍺ ⍵⍵ ⍵⌷⍨⊂P)@P)⍵⊣P←¯1 0 1+⍸1<⍵}
msimp ← {((⌽⍣A)0 0 2)+(B@2)P⊣A B←⍺ rule¨⊂P←⍵-0 2 0}
@chshersh
chshersh / parser-combinators-vs-parser-generators.md
Last active April 24, 2025 04:58
Per criterion comparison of Parser Generators and Parser Combinators

Legend:

  • ➖ poor (impossible or very hard to achieve)
  • ➕ good (possible but requires some dancing)
  • ✔️ excellent (very easy to achieve/have)

PC stands for parser combinators and PGparser generators.

Property Generators Combinators Description
Power ✔️ LALR ➕ LL(∞) PC can't handle left-recursive grammars (though, there's some article¹...).
@ObserverOfTime
ObserverOfTime / WA2-Ubuntu.md
Last active February 11, 2024 07:05
Install and patch White Album 2 on Linux

For Ubuntu and other Debian-based distros

This gist is deprecated. You can find the latest instructions here.

1: Enable Japanese Locale

Check whether it's already enabled:

$ locale -a | grep ja
@nandajavarma
nandajavarma / Timsort
Created February 17, 2017 19:47
Timsort implementation using Python
#!/usr/lib/python
# -*- coding: utf-8 -*-
#
# This is a re-implementation of Python's timsort in Python
# itself. This is purely for learning purposes. :)
# References: [
# https://en.wikipedia.org/wiki/Timsort,
# http://wiki.c2.com/?TimSort
# ]
#
@praeclarum
praeclarum / AlgorithmW.fs
Last active February 2, 2025 14:29
Algorithm W - or Hindley-Milner polymorphic type inference - in F#
module AlgorithmW
// HINDLEY-MILNER TYPE INFERENCE
// Based on http://catamorph.de/documents/AlgorithmW.pdf
// (Now at http://web.archive.org/web/20170704013532/http://catamorph.de/documents/AlgorithmW.pdf)
type Lit =
| LInt of int
| LBool of bool
@14427
14427 / hkt.rs
Last active September 26, 2025 13:52
Higher-kinded type trait
use std::rc::Rc;
trait HKT<U> {
type C; // Current type
type T; // Type with C swapped with U
}
macro_rules! derive_hkt {
($t:ident) => {
impl<T, U> HKT<U> for $t<T> {
@poizan42
poizan42 / inf-primes.v
Created November 27, 2014 20:08
Proof of the infinitude of primes
Require Import Coq.ZArith.ZArith.
Require Import Coq.ZArith.Znumtheory.
Require Import Coq.Sets.Ensembles.
Require Import Coq.Sets.Finite_sets.
Require Import Coq.PArith.BinPos.
Definition Z_ens := Ensemble Z.
Print Finite.
Print Empty_set.
Definition is_empty_set U A := forall x, ~(In U A x).
@unhammer
unhammer / merlin-init.sh
Last active February 12, 2023 05:40
Create .merlin file for a project with all your ocamlfind packages and .opam sources in there
#!/bin/sh
if test -f .merlin; then
echo ".merlin already exists, bailing out ..." >&2
exit 1
else
# You could add your default EXT's and such to this list:
@jozefg
jozefg / closconv.lhs
Last active June 4, 2025 10:59
Tutorial on Closure Conversion and Lambda Lifting
This is my short-ish tutorial on how to implement closures in
a simple functional language: Foo.
First, some boilerplate.
> {-# LANGUAGE DeriveFunctor, TypeFamilies #-}
> import Control.Applicative
> import Control.Monad.Gen
> import Control.Monad.Writer
> import Data.Functor.Foldable