Skip to content

Instantly share code, notes, and snippets.

Avatar

Alain Armand idkjs

View GitHub Profile
@idkjs
idkjs / extensions.sh
Last active Aug 30, 2021
rename extensions
View extensions.sh
#!/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"
View Private_Mailserver_M1.md

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 Aug 12, 2021
Slack clone raw sql schema
View slack.sql
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 Jul 11, 2021
Rescript + Reason + OCaml@4.12.0 for `let.opts` in Rescript
View Demo.res
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 Jul 6, 2021
Immutable List Style
View yawaramin.md

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 Jul 6, 2021
node-glob reasonml web
View README.md

reason-glob

BuckleScript bindings to node-glob.

Status: Very basic, but functional

Example

Glob.glob("**/*.js", (_, files) => Array.iter(Js.log, files));
View fastreplace.sh
#!/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 Jul 21, 2021
Using the `@tailcall` annotation in ReasonML
View tailcall.re
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);
};
@idkjs
idkjs / GroupWhile.re
Created Jul 1, 2021
GroupWhile for Rescript/Reason using Belt lib
View GroupWhile.re
type nonrec t('a) = list('a);
let rec dropWhile = (t, ~f) =>
switch (t) {
| [] => []
| [x, ...rest] =>
if (f(x)) {
dropWhile(rest, ~f);
} else {
t;
@idkjs
idkjs / try_finally.re
Created Jun 27, 2021
try a function example
View try_finally.re
let try_finally = (~always, f) =>
switch (f()) {
| x =>
always();
x;
| exception e =>
always();
raise(e);
};