Skip to content

Instantly share code, notes, and snippets.

View idkjs's full-sized avatar

Alain Armand idkjs

View GitHub Profile
module Any = {
// borrowed from https://github.com/cca-io/rescript-material-ui/blob/master/public/rescript-material-ui/src/Any.res
type t;
external make: 'a => t = "%identity";
external fromString: string => t = "%identity";
external fromInt: int => t = "%identity";
external unsafeToString: 'a => string = "%identity";
external unsafeToInt: 'a => int = "%identity";
external unsafeGetValue: t => 'a = "%identity";
@idkjs
idkjs / README.md
Last active December 28, 2021 14:16
TowersOfHanoi in OCaml

Towers of Hanoi from https://youtu.be/DCKOcY-k2Es

  • add unix.cma to inline using the Unix library when calling the Hanoi.ml program. You could have included it in a dune file.
ocaml unix.cma hanoi.ml
@idkjs
idkjs / extensions.sh
Last active August 30, 2021 15:38
rename extensions
#!/bin/bash
echo "Enter the target directory "
read -r target_dir
cd "$target_dir" || exit
echo "Enter the file extension to search without a dot"
read -r old_ext
echo "Enter the new file extension to rename to without a dot"

Private Mailserver with Postfix, Dovecot and Fetchmail on macOS Big Sur M1

This is a simple installation and configuration manual to setup a private mailserver. The instructions will be continued in future...

Requirements

  • Apple M1 with macOS Big Sur but it should working at Intel Macs 64-bit too.
  • Replacement for the missing mail and imap services in the macOS Server
  • Receiving and sending emails of all accounts (private and business)
  • Using Postfix, Dovecot and Fetchmail
@idkjs
idkjs / slack.sql
Created August 12, 2021 11:30
Slack clone raw sql schema
CREATE TABLE IF NOT EXISTS "users" (
"id" SERIAL,
"username" VARCHAR(255) UNIQUE,
"email" VARCHAR(255) UNIQUE,
"password" VARCHAR(255),
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL,
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL,
UNIQUE ("username"),
UNIQUE ("email"),
PRIMARY KEY ("id")
@idkjs
idkjs / Demo.res
Created July 11, 2021 10:00
Rescript + Reason + OCaml@4.12.0 for `let.opts` in Rescript
let a = Some(10);
let b = Some(3);
Js.log2("using ocaml 4.12 compiled reasonml let.opt in Rescript", Opts.z(a,b));
@idkjs
idkjs / yawaramin.md
Last active July 6, 2021 20:48
Immutable List Style

This was a great example. I wanted to take some time to demonstrate an idiomatic, immutable-style list-processing approach to solving this. In FP, the most powerful general-purpose immutable list-processing functions are the fold functions. They iterate through a list one item at a time, keeping track of a 'current value' which can be anything, and apply some folding function to that current value and each list item to come up with the next 'current value'. There are different types of folding functions which work in slightly different ways, you can learn about them in functional programming books or courses.

Long story short, the appropriate fold function for your list is List.fold_left, which walks through each item of your list from left to right, applying the given function. A simple example: let result = List.fold_left (/) 36 [1, 2, 3]. Now, result = 6, which is 36 / 1 / 2 / 3.

Here's the solution to your example using List.fold_left:

type data_item = {
  symbol: string,
  next: bool,
@idkjs
idkjs / README.md
Last active July 6, 2021 19:32
node-glob reasonml web

reason-glob

BuckleScript bindings to node-glob.

Status: Very basic, but functional

Example

Glob.glob("**/*.js", (_, files) => Array.iter(Js.log, files));
#!/bin/sh
# cd ..
files=$(find src -name "*.re" && find src -name "*.rei")
echo $files
for file in $files
do
echo $PWD/$file
# fastreplacestring $file "ReasonReact.NoUpdate" "NoUpdate"
fastreplacestring $file "ReasonReact.Update" "Update"
@idkjs
idkjs / tailcall.re
Last active July 21, 2021 22:34
Using the `@tailcall` annotation in ReasonML
let sum = n => {
let rec loop = (n, k) =>
if (n == 0) {
k(0);
} else {
([@tailcall] loop)(n - 1, x => k(x + n));
};
([@tailcall] loop)(n, x => x);
};