Skip to content

Instantly share code, notes, and snippets.

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

Enzzo souenzzo

🚴‍♂️
💨 💨
View GitHub Profile
@souenzzo
souenzzo / find-unused-deps.clj
Created November 4, 2019 17:09
!!!! QUCK'n'DIRTY SOLUTION !!!!
(let [{:keys [namespace-usages]} (:analysis (kondo/run! {:lint ["src/main"
"src/old"]
:config {:output {:analysis true}}}))
url->splited-path #(into []
(comp (map (memfn getFileName))
(map str)
(take-while (complement string/blank?)))
(iterate (fn [x] (when x (.getParent x)))
(Paths/get (new URI (-> (str %)
(string/replace #"^jar\:"
@souenzzo
souenzzo / deps.edn
Last active July 3, 2023 15:15
Browser presign POST upload using AWS-SDK
;; 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"}
(-> (js/fetch "/api.json")
(.then (fn [response]
;; I can access the response/headers, but can't access the json/body. :(
(.json response)))
(.then (fn [json]
;; I can access the json/body, but can't access the response/headers. :(
...)))
(-> (js/fetch "/api.json")
@souenzzo
souenzzo / deps.edn
Last active September 26, 2021 10:52
Clojure version of "java quickstart" from gsheets. https://developers.google.com/sheets/api/quickstart/java
;; run with
;; clj -Sdeps '{:deps {gdocs {:git/url "https://gist.github.com/souenzzo/df540002607b15378f8014237e499fdd" :sha "fee00617c75fc24c74931aa4200f74666c5b66b6"}}}' -m gdocs
{:paths ["."]
:deps {org.clojure/clojure {:mvn/version "1.10.0"}
com.google.api-client/google-api-client {:mvn/version "1.28.0"}
com.google.oauth-client/google-oauth-client-jetty {:mvn/version "1.28.0"}
com.google.apis/google-api-services-sheets {:mvn/version "v4-rev566-1.25.0"}}}
(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
(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)
(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)]

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
(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

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.