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
@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 / 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 / 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)))
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 / .env
Created August 13, 2020 16:39
Upload progress Node.js + Axios
AWS_ACCESS_KEYID=
AWS_SECRET_KEY=
BUCKET=
;;
;; 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)
;;
;; 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))))
;;
;; O web server pode seguir o mesmo protocolo
;; e principios que o banco de dados.
;;
(defrecord WebServer [port app]
component/Lifecycle
(start [component]
(assoc component
::jetty
;;
;; Todo o ciclo de vida do banco de dados
;; fica encapsulado em um componente.
;;
(defrecord Database [uri database connection]
component/Lifecycle
(start [component]
(let [{:keys [conn db]} (mg/connect-via-uri uri)]
(assoc component :database db
(defrecord Database [uri database connection])
(defn create-database [uri]
(let [{:keys [db conn]} (mg/connect-via-uri uri)]
(map->Database {:uri uri
:database db
:connection conn})))