Skip to content

Instantly share code, notes, and snippets.

View renatoalencar's full-sized avatar
🍵
Smashing the stacks

Renato Alencar renatoalencar

🍵
Smashing the stacks
View GitHub Profile
;;
;; Associa um valor `value` a um chave `key` no
;; primeiro argumento da funcao `f`.
;;
;; Espera-se que `f` seja um handler que possa
;; ser usado com o Ring.
;;
(defn wrap-assoc [f key value]
(fn [request] (f (assoc request key value))))
;;
;; Apesar de podermos fazer isso diretamente no `-main`, aqui
;; podemos separar a responsabilidade de interpretar as
;; opcoes e passar para os respectivos constructores dos
;; componentes.
;;
(defn system [& options]
(let [{:keys [database-url port]} options]
(component/system-map
:database (new-database database-url)
@renatoalencar
renatoalencar / .env
Created August 13, 2020 16:39
Upload progress Node.js + Axios
AWS_ACCESS_KEYID=
AWS_SECRET_KEY=
BUCKET=
let valid_cpf cpf =
let aux size =
let sum = ref 0 in
for i = 0 to (size - 2) do
sum := !sum + cpf.(i) * (size - i);
done;
!sum * 10 mod 11
in
(aux 10) == cpf.(9) && (aux 11) == cpf.(10)
@renatoalencar
renatoalencar / dune
Last active November 9, 2021 21:37
OCaml HTTP server example with Piaf
(executable
(name server)
(libraries ssl piaf yojson ppx_deriving_yojson.runtime)
(preprocess (pps ppx_deriving_yojson)))
@renatoalencar
renatoalencar / Dockerfile
Created November 10, 2021 13:08
OCaml static linking with Opam for AWS lambda runtime
FROM alpine
RUN apk add opam git musl-dev make m4 gcc bubblewrap bash coreutils pkgconfig openssl-libs-static openssl-dev
RUN opam init --disable-sandboxing
RUN opam install -y ocaml-base-compiler lambda-runtime dune
WORKDIR /app
COPY . .
@renatoalencar
renatoalencar / Note.md
Created November 23, 2021 21:54
Clojure for Tezos

Clojure for Tezos

  • Endpoints are declared by adding an :entrypoint metadata at the function declaration, which could further extended to a defentrypoint macro.
  • Due to the typed nature of Michelson, the code must be typed to properly be translated to code:
    • Type declarations should use the type function (or macro?) to declare types for namespace defined variables.
    • Extra type annotation could be done by using metadata.
    • Need for a type checker, which I don't know how to implement (I don't know to how to build a backend also, but don't tell anyone).
    • Michelson types need a correspondence for Clojure literals, while some are possible, conjunction and disjunction types are not available for Clojure.
  • Some types have an extra challenge, like option and or, because Clojure doesn't have the proper idioms to deal with it, I should define a few patterns to describe how to interpret them, mainly option.
  • To descrease the overhead for type inference, some literals are going to be used for natur
@renatoalencar
renatoalencar / traversal.js
Last active December 3, 2021 15:34
React fiber tree traversal
let root = $0._reactRootContainer._internalRoot
let node
let count
let map
node = root.current
count = 0
map = new Map()
@renatoalencar
renatoalencar / day01.ml
Last active October 31, 2023 13:47
Advent of Code 2021 Solutions in OCaml
let read_lines () =
let rec aux lines =
try
let line = input_line stdin in
aux @@ line :: lines
with End_of_file ->
lines
in
List.rev @@ aux []
@renatoalencar
renatoalencar / socks4.ml
Last active December 11, 2021 12:17
Socks4 and socks5
type version = Socks4
type command = Connect | Bind
type port = int
type request = { version: version
; command: command
; destport: port