Skip to content

Instantly share code, notes, and snippets.

(* a + b (mod m) *)
let addmod a b m =
assert (0 <= a && 0 <= b);
let a = a mod m in
let b = b mod m in
if a < m - b then
(* Case A: a + b < m *)
a + b
else
(* Case B: a + b >= m
@youz
youz / grass.ml
Last active October 12, 2022 08:42 — forked from ytomino/grass.ml
ocaml implementation of http://www.blue.sky.or.jp/grass/
type token = T_w | T_W | T_v | EOF;;
let rec scan s i = (
let length = String.length s in
if i >= length then length, EOF else
match s.[i] with
| 'W' -> i + 1, T_W
| 'w' -> i + 1, T_w
| 'v' -> i + 1, T_v
| '\xef' -> (* W : EF BC B7, v : EF BD 96, w : EF BD 97 *)
@mstewartgallus
mstewartgallus / gadts.rs
Last active November 2, 2019 18:59
Gadts in Rust
/// This type is only every inhabited when S is nominally equivalent to T
pub type Is <S, T> = Is_ <S, T>;
priv struct Is_ <S, T>;
// Construct a proof of the fact that a type is nominally equivalent
// to itself.
pub fn Is <T> () -> Is <T, T> { Is_ }
pub impl <S, T> Is_ <S, T> {
@waltarix
waltarix / zsh-utf8mac-completion.patch
Created November 29, 2011 04:00
zsh: Completion treats filename that is encoded in UTF-8-MAC as UTF-8.
diff --git a/Src/utils.c b/Src/utils.c
index 26e2a5c..04c3783 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4244,6 +4244,13 @@ mod_export char *
zreaddir(DIR *dir, int ignoredots)
{
struct dirent *de;
+#ifdef HAVE_ICONV
+ static iconv_t conv_ds = (iconv_t)NULL;
#!/bin/sh
TRUNK_HASH=`git show-ref --hash remotes/trunk`
REV=`git svn find-rev "$TRUNK_HASH"`
if [ "$#" -eq 0 ]
then
HASHES="$TRUNK_HASH..HEAD"
else
HASHES="$1"