Skip to content

Instantly share code, notes, and snippets.

View rdavison's full-sized avatar

Richard Davison rdavison

  • Solvuu
  • New York, New York
View GitHub Profile
@rdavison
rdavison / karabiner.edn
Last active September 7, 2023 20:51
My GokuRakuJoudo Config
{
:applications {
:codes ["^com\\.microsoft\\.VSCode$" "^com\\.googlecode\\.iterm2$"]
}
:input-sources {
:mtgap {
:input_source_id "org.sil.ukelele.keyboardlayout.graphite.mtgap"
:language "en"
}
}
open Printf
(* NOTE:
* 1) In OCaml syntax, function application is done with a space, for example:
* Java: f(x, y, z)
* OCaml: f x y z
* 2) types are read backwards, for example:
* `int list` is read as "list of ints"
* `(int, string) result is read as "result of ints and strings"
open Printf;
module Unicode = Zed_utf8;
let isPalindrome = aString => {
Unicode.compare(aString, Unicode.rev(aString)) == 0
};
let main = {
let testCases = [|
@rdavison
rdavison / diamond_overkill.re
Last active March 22, 2018 23:17
Implements the same diamond printing algorithm using the y-combinator (fix). Needs to be compiled with the -rectypes flag
open Core;
let fix = (f, g) => ((x, a) => f(x(x), a))((x, a) => f(x(x), a), g);
let make_line = (n, width) => {
let blanks = String.make((width - n) / 2, ' ');
let stars = String.make(n, '*');
blanks ++ stars ++ blanks ++ "\n";
};
@rdavison
rdavison / diamond.re
Last active March 22, 2018 22:41
Prints diamonds to the screen
open Core;
let make_line = (n, width) => {
let blanks = String.make((width - n) / 2, ' ');
let stars = String.make(n, '*');
blanks ++ stars ++ blanks ++ "\n";
};
let rec make_rest = (n, width, concat) =>
if (n <= 0) {
@rdavison
rdavison / foo.ml
Last active September 19, 2017 05:36
Fatal error: exception (Failure "initializing Random with a nondeterministic seed is forbidden in inline tests")
let%test "two plus two is five" =
let ( + ) 2 2 = 5 in
(2 + 2) = 5
@rdavison
rdavison / applicativeDemo.hs
Last active July 11, 2017 14:37
Applying a function to lists using applicative functors
import Control.Applicative
-- Create a Person data type
data Person = Person {
name :: String,
age :: Int,
language :: String
} deriving (Show)
-- Person is a data constructor, and has a function signature of