Skip to content

Instantly share code, notes, and snippets.

View davesnx's full-sized avatar

David Sancho davesnx

View GitHub Profile
@davesnx
davesnx / Makefile
Last active January 3, 2024 17:14
importMaps are cool
dev:
npx http-server -o .
open Ppxlib
module Builder = Ast_builder.Default
type target = Native | Js
let mode = ref Native
module Effect = struct
(* TODO: [%effect] is a little incomplete, only works with useEffect0 (not other useEffectX, neither useLayoutEffects) *)
let extractor = Ast_pattern.(__')
@davesnx
davesnx / print-rescript-parsetree.sh
Last active December 4, 2023 14:11
ReScript Parsetree print
npx bsc -dparsetree wat.res
npx bsc -dparsetree wat.ml
npx bsc -format wat.ml
@davesnx
davesnx / index.md
Last active December 4, 2023 14:03
Safer Tailwind with OCaml-derived languages

Safer Tailwind with OCaml-derived languages (OCaml, Reason, ReScript or Melange)

Tailwind is optimised to work with JavaScript/TypeScript ecosystems, but other languages might have good integrations also.

This is the case for OCaml-derived languages that are used to do Frontend development. For the most part, a tighter integration might not be needed and using the Tailwind setup guide and regular classNames with strings is good enought.

let make = (~text) => {
  <h1 className="text-3xl font-bold underline">{React.string(text)}<h1>
box(
{
padding: 5,
width: "320px",
border: "sm",
onClick: onClick,
onMouseLeave: onMouseLeave,
},
[
stack({ gap: 2, align: "center" }, [
@davesnx
davesnx / Makefile-help
Last active September 26, 2022 18:22
Print other makefiles commands as help
.PHONY: help # Set default action to be help!
help:
@echo "List of available make commands";
@echo "";
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}';
@echo "";
# Add double ## comments on the same line as the dependencies and will be printed out when running help
# Don't add them if you don't want to appear on help!
@davesnx
davesnx / index.js
Created August 2, 2022 08:08
Package manager check
const lockfileSpecs = [
{
checkfile: ".yarnrc.yml",
lockfile: "yarn.lock",
command: "yarn",
version: "2",
arguments: ["install", "--immutable"]
},
{
checkfile: "yarn.lock",
@davesnx
davesnx / myComponent.ml
Created December 13, 2021 10:11 — forked from jordwalke/myComponent.ml
React OCaml API
open ReactDOM
module MyComponent = struct
(* Component Properties *)
type props = {count: int}
(* Hey, state can be any type! *)
type state = string
(* Initializer *)
@davesnx
davesnx / README.md
Last active September 10, 2021 10:52
Using ocaml-lsp with Reason syntax

Configure VSCode with ocaml-lsp, esy and Reason syntax with ReScript/bs-platform.

It's a non-common setup

but I find very useful, I keep liking more the Reason syntax and the ocaml-lsp experience it's much better than the rescript extension. Notably with the CodeLens support https://code.visualstudio.com/blogs/2017/02/12/code-lens-roundup with https://github.com/ocaml/ocaml-lsp.

So, If you want to keep using Reason syntax targeting the browser/node and have a good editor support, follow this: