Skip to content

Instantly share code, notes, and snippets.

View melwyn95's full-sized avatar
🐫
OCaml

Melwyn Saldanha melwyn95

🐫
OCaml
View GitHub Profile
@melwyn95
melwyn95 / zebra_puzzle.ml
Created February 18, 2023 17:15
A naive & hacky solution for zerbra puzzle
type nationality =
English
| Spainiard
| Ukrainian
| Japanese
| Norwegian
let print_nationality = function
English -> "English"
| Spainiard -> "Spainiard"
@melwyn95
melwyn95 / FA2
Created January 16, 2022 08:53
Notes
TZIP-21 (https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-21/tzip-21.md)
TZIP-16 (https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-16/tzip-16.md)
TZIP-12 (https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-12/tzip-12.md)
- interface
single token type & multi token type
- token transfer semantics
- metadata
token & contract level
(* Implementation for Algorithm-W tutorial in OCaml
Reference: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.7733&rep=rep1&type=pdf
*)
(* trivial utils *)
module SMap = Map.Make(String)
module SSet = Set.Make(String)
let rec zip xs ys =
match xs, ys with
@melwyn95
melwyn95 / esy.lock.index.json
Created October 28, 2021 07:00
esy - project with different version of same package
{
"checksum": "438ad176435950ec970bbda6417e5c3b",
"root": "ligo-main@link-dev:./esy.json",
"node": {
"temp-ligo-bin@0.25.2@d41d8cd9": {
"id": "temp-ligo-bin@0.25.2@d41d8cd9",
"name": "temp-ligo-bin",
"version": "0.25.2",
"source": {
"type": "install",
@melwyn95
melwyn95 / result.c
Last active September 13, 2021 04:25
OCaml C stubs
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
// Reference: http://decapode314.free.fr/ocaml/ocaml-wrapping-c.html
// Reference: https://ocaml.org/manual/intfc.html
// This stub return a (int,string) result
value esy_test_result(value unit) {
@melwyn95
melwyn95 / union_find.ml
Created September 5, 2021 06:44
Union Find
let make () : elem = ref @@ Root 0
let find (x : elem) : elem =
let rec aux (x : elem) (xs : elem list) =
match !x with
| Root _ ->
let () = x := Root (List.length xs) in
let () = List.iter (fun x' -> x' := Link x) xs in
x
@melwyn95
melwyn95 / pnp.js
Created August 16, 2021 04:31
PNP js generated by esy
#!/usr/bin/env node
/* eslint-disable max-len, flowtype/require-valid-file-annotation, flowtype/require-return-type */
/* global packageInformationStores, $$BLACKLIST, $$SETUP_STATIC_TABLES */
// Used for the resolveUnqualified part of the resolution (ie resolving folder/index.js & file extensions)
// Deconstructed so that they aren't affected by any fs monkeypatching occuring later during the execution
const {statSync, lstatSync, readlinkSync, readFileSync, existsSync, realpathSync} = require('fs');
const Module = require('module');
const path = require('path');
@melwyn95
melwyn95 / sha1.rkt
Last active July 24, 2021 14:14
SHA-1 implemented in Racket
#lang racket
;;;;;;;;;;;;;;;; Hex conversion ;;;;;;;;;;;;;;;;
(define (hex-char-to-bin-list c)
(cond [(eq? #\0 c) (list 0 0 0 0)]
[(eq? #\1 c) (list 0 0 0 1)]
[(eq? #\2 c) (list 0 0 1 0)]
[(eq? #\3 c) (list 0 0 1 1)]
[(eq? #\4 c) (list 0 1 0 0)]
[(eq? #\5 c) (list 0 1 0 1)]
@melwyn95
melwyn95 / Palindrome.ts
Created June 23, 2021 02:13
TS type-system hacks
type str = "racecar"
// will require a-z
type Alphabet = 'r' | 'a' | 'c' | 'e'
type ReverseStr<Str extends string> =
Str extends ''
? Str
: Str extends `${infer Chr}${infer Str}`
? Chr extends Alphabet
open Angstrom;
type line =
| NewLine
| PassPort(string);
let newLine = char('\n') *> return(NewLine);
let passPort =
take_while(char => {char != '\n'}) >>= (s => return(PassPort(s)));
let parse = sep_by(newLine, passPort);
let string = "eyr:2021 hgt:168cm hcl:#fffffd pid:180778832 byr:1923 ecl:amb iyr:2019 cid:241
hcl:#341e13 ecl:lzr eyr:2024 iyr:2014 pid:161cm byr:1991 cid:59 hgt:150cm