Skip to content

Instantly share code, notes, and snippets.

Avatar
🚴‍♂️
💨 💨

Enzzo souenzzo

🚴‍♂️
💨 💨
View GitHub Profile
View lazy-pedestal.clj
(require '[io.pedestal.http :as http]
'[io.pedestal.test :refer [response-for]]
'[clojure.java.io :as io]
;; clojure.data.json isn't fast.
;; if you need speed, look at cheshire
'[clojure.data.json :as j])
(let [get-lazy-vs (fn []
;; just a dummy lazy get function
;; it takes 100ms to get each element
View download-package-lock.clj
(ns build
(:require [clojure.tools.build.api :as b]
[shadow.cljs.devtools.api :as shadow.api]
[shadow.cljs.devtools.server :as shadow.server]
[cheshire.core :as json]
[clojure.java.io :as io]
[clojure.string :as string])
(:import (org.apache.commons.compress.archivers ArchiveStreamFactory)
(java.util.zip GZIPInputStream CheckedInputStream Adler32)
(java.security MessageDigest DigestInputStream)
View eql-select.clj
(defn select-as
[value query]
(letfn [(selector [{:keys [children]
:as node}
value]
(cond
(map? value) (into {}
(keep (fn [{:keys [key params]
:as node}]
(when-let [[_ v] (find value key)]
View clj-async.md

How to turn your sync API into an async one

Let's suppose that you have a sync API send

(send params)

This API has at least 2 behaviors:

  1. Return a value
  2. Throw an exception
View spy.clj
(def spy-plugin
{::pc/wrap-resolve (fn [resolve]
(fn [env input]
(let [resolver-sym (-> env ::pc/resolver-data ::pc/sym)
_ (prn {:sym resolver-sym
:input input
:entity (p/entity env)})
output (resolve env input)]
(prn {:sym resolver-sym
:output output
View desafio.md

Função promover/rebaixar (parte 1)

Dado uma coleção coll, por exemplo, [:a :b :c :d :e] e um predicado pred, por exemplo #{:c}, implementar uma função promover que recebe (promover #{:c} [:a :b :c :d :e]) e retorna a coleção com o elemento selecionado "uma posição a frente": [:a :c :b :d :e]

Implementar também a função rebaixar, com a mesma assinatura, porém resulta em [:a :b :d :c :e]

Os casos de borda (elementos repetidos, agrupamentos degenerados) não são importantes.

View foo.clj
(ns digital-wallet.main-test-old
(:require [clojure.test :refer [deftest]]
[midje.sweet :refer [fact =>]])
(:import (clojure.lang ILookup)
(java.lang AutoCloseable)
(java.util Properties)
(org.apache.kafka.common.serialization Serdes Serdes$StringSerde Serdes$LongSerde)
(org.apache.kafka.streams TopologyTestDriver StreamsConfig Topology KeyValue)
(org.apache.kafka.streams.processor.api ProcessorSupplier Processor ProcessorContext Record)
(org.apache.kafka.streams.state Stores KeyValueStore)
View eql-hodur.clj
(ns eql-hodur
(:require [edn-query-language.core :as eql]
[clojure.spec.alpha :as s]
[datascript.core :as ds]))
(defn add-prop
[prop {:keys [children]
:as node}]
(if (contains? node :children)
(assoc node
@souenzzo
souenzzo / deps.edn
Last active Sep 8, 2020
Browser presign POST upload using AWS-SDK
View deps.edn
;; reference
;; https://github.com/kamil-perczynski/s3-direct-browser-upload
{:deps {org.clojure/clojure {:mvn/version "1.10.1"}
hiccup/hiccup {:mvn/version "2.0.0-alpha2"}
io.pedestal/pedestal.jetty {:mvn/version "0.5.8"}
io.pedestal/pedestal.service {:mvn/version "0.5.8"}
commons-codec/commons-codec {:mvn/version "1.15"}
com.cognitect.aws/api {:mvn/version "0.8.474"}
com.cognitect.aws/endpoints {:mvn/version "1.1.11.842"}
@souenzzo
souenzzo / cola.edn
Created Jun 20, 2020
lambda-io.demo
View cola.edn
;; hello eql
[:app/hello]
;; data->shape
{:app/hello "ok"}
{:app/hello "ok"
:app/users [{:user/id 1
:user/username "2"
:user/addresses [{:address/description "a"
:address/number 1}]}]}