Skip to content

Instantly share code, notes, and snippets.

View souenzzo's full-sized avatar
🚴‍♂️
💨 💨

Enzzo souenzzo

🚴‍♂️
💨 💨
View GitHub Profile
#!/usr/bin/env clj
;; also works: #!/usr/bin/env lumo
;; quoting; still not work on cljs
(let [unreserved? (into (sorted-set)
(comp (map (fn [[k v]]
(prn (mapv int [k v]))
(range (int k) (inc (int v)))))
cat (map char))
{\a \z \A \Z \0 \9 \- \- \. \. \_ \_ \~ \~})
@souenzzo
souenzzo / http-socket-server.clj
Last active May 6, 2020 13:16
tiny http server via java sockets in clojure
#!/usr/bin/env clojure
(import (java.net ServerSocket))
(require '[clojure.string :as string] '[clojure.java.io :as io])
(letfn [(req-line+headers [in]
(binding [*in* in]
(loop [headers []]
(let [line (read-line)]
(if (string/blank? line)
@souenzzo
souenzzo / build.clj
Last active August 15, 2020 14:17
Using material-ui.com from cljs. Still a fat build
;; this can be used on figwheel or in "any" cljs build api
;; at the first time, create a empty package.json with `{}` inside and `yarn add react webpack webpack-cli react-dom @material-ui/core`
;; you need to run "yarn install" and "yarn webpack" BEFORE this
;; !!!! this is a dev build !!!!
(def dev-build
'{:id "dev"
:source-paths ["src" "dev"]
:figwheel {:on-jsload cljs.user/on-jsload}
:compiler {:main cljs.user
:asset-path "/js/out"
(require '[datomic.api :as d])
(defn undo-transact
[db tx]
(let [ref? (set (d/q '[:find [?ident ...] :where [?e :db/ident ?ident] [?e :db/valueType :db.type/ref]] db))
ident (into {} (d/q '[:find ?id ?ident :where [?id :db/ident ?ident]] db))
hist (d/history db)
data-from-tx (d/q '[:find ?e ?a ?v ?tx ?op
:in $ ?tx
:where
{ "foo": "bar"
, "var": [ 1
, 2
, 3
]
}

Keybase proof

I hereby claim:

  • I am souenzzo on github.
  • I am souenzzo (https://keybase.io/souenzzo) on keybase.
  • I have a public key ASD0ZWrUwMXEiq6v92gweqkx3Bc0RIixtMqfbhEdEdLrMQo

To claim this, I am signing this object:

@souenzzo
souenzzo / foo.clj
Created May 31, 2018 18:14
desafios do lambda WIP
(defn str->index
[s]
(let [[nodes & edges] (string/split-lines s)
split #(string/split % #",")
nodes (split nodes)]
(reduce (fn [index [node edges]]
(let [ke (zipmap nodes edges)]
(into index (for [[k v] ke
:when (not (string/blank? v))]
[[node k] (bigint v)]))))
@souenzzo
souenzzo / datomc-on-js-graal.clj
Created May 23, 2018 02:35
How to access datomic from javascript in graalvm
;; Hello world with clojure + js
;; (import '(org.graalvm.polyglot Context))
(let [polyglot (-> (doto (Context/newBuilder (into-array ["js"]))
(.allowAllAccess true))
(.build))]
(.eval polyglot "js" "
console.log('hello');
"))
// Programação "OO Tradicional"
const express = require('express')
const app = express()
app.get('/', indexGet)
app.post('/', indexPost)
// Programação "Data Driven"
@souenzzo
souenzzo / async.js
Created April 14, 2018 12:32
Compare async performance with sync.
const fibsync = n => {
if (n <= 1) return 1
const a = fibsync(n - 1)
const b = fibsync(n - 2)
return a + b
}
const fibasync = async (n) => {
if (n <= 1) return 1