Skip to content

Instantly share code, notes, and snippets.

View hyphenrf's full-sized avatar

Haz hyphenrf

  • Egypt
View GitHub Profile
Walter Bright's MEM Package
---------------------------
PREFACE:
--------
The files, MEM.H and MEM.C which constitute the MEM package were originally
published in the March-April 1990 edition of Micro Cornucopia magazine, now
sadly out of print. The files as they appear in SNIPPETS have been edited
@hyphenrf
hyphenrf / upsize
Last active May 19, 2021 01:34
get eopkg update size in per-package detail
#!/usr/bin/env python2
from pisi.api import *
from pisi.util import human_readable_size
from os.path import basename as b
from sys import argv
ctx = set()
@hyphenrf
hyphenrf / pyfun.py
Created April 20, 2021 11:52
Does this make you angry?
import functools
c = lambda f: lambda g: lambda x: f (g (x))
add = lambda x: lambda y: x + y
const = lambda x: lambda y: x
uncurry = lambda f: lambda x, y: f (x) (y)
succ = add (1)
fold = lambda f: lambda z: lambda xs: functools.reduce(uncurry(f), xs, z)
len = fold (c (const) (succ)) (0)
#> shell doesn't have multiline comments
: <<comment
ok
buddy
here's
your
multiline
comment
@hyphenrf
hyphenrf / xxd-r.hs
Last active May 9, 2021 00:45
a utility equivalent to `xxd -r -ps` for systems with limited xxd implementations
{-# language OverloadedStrings #-}
import Prelude hiding (getLine, putStr, filter, length, take, drop)
import Data.ByteString
import Data.Maybe
main = do
ln <- getLine
putStr $ f ln -- putStr and getLine from ByteString
let rec perm = function
| [] -> []
| [x] -> [[x]]
| xs ->
let rec aux i ls =
let (l,r) = splitat i ls in
match r with
| [] -> []
| h::r_ ->
let rest = l @ r_ in
@hyphenrf
hyphenrf / combinations.hs
Created June 15, 2021 11:28
you've heard of permutations, get ready for this
-- possibly the worst implementation out there but
combinations [] = []
combinations xs = go (length xs) (map pure xs) xs where
go 1 zs __ = zs
go n zs ys = [ y:z | y <- ys, z <- go (n-1) zs ys ]
@hyphenrf
hyphenrf / show.c
Last active January 1, 2022 19:30
#define show(fmt, ...) (printf("%s: ", #__VA_ARGS__), printf(fmt, __VA_ARGS__))
#define show8(x) printf(#x":\t%02hhx (%hhd)\n", x, x)
@hyphenrf
hyphenrf / choose.curry
Last active January 27, 2022 15:10
nondeterministic choice implemented in different languages
{-# OPTIONS_FRONTEND -Wno-overlapping #-}
import AllSolutions
insert :: a -> [a] -> [a] -- warning: overlapping patterns = ndet
insert x xs = x : xs
insert x (y:ys) = y : insert x ys
perm :: [a] -> [a]
perm [] = []
@hyphenrf
hyphenrf / gadt_of_prolog.ml
Last active October 10, 2022 23:00
this actually works :D
(*
nat(z).
nat(s(N)) :- nat(N).
plus(N, z, N).
plus(N, s(M), s(A)) :- plus(N, M, A).
mult(_, z, z).
mult(N, s(M), B) :- mult(N, M, A), plus(N, A, B).