Skip to content

Instantly share code, notes, and snippets.

@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}]}]}
@souenzzo
souenzzo / deps.edn
Last active Jun 5, 2020
Clojure version of "java quickstart" from gsheets. https://developers.google.com/sheets/api/quickstart/java
View deps.edn
;; 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"}}}
View pathom.clj
(let [conn (doto (ds/create-conn {:user/addresses {:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many}
:user/id {:db/unique :db.unique/identity}})
(ds/transact! [{:user/id 1
:user/addresses [-1 -2]}
{:user/id 2
:user/addresses [-2 -3]}
{:user/id 3
:user/addresses [-4]}
{:db/id -1
@souenzzo
souenzzo / http-socket-server.clj
Last active May 6, 2020
tiny http server via java sockets in clojure
View http-socket-server.clj
#!/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)
View java_http.clj
(ns com.wsscode.pathom.diplomat.http.java-http
(:require [com.wsscode.pathom.diplomat.http :as http]
[clojure.spec.alpha :as s]
[clojure.core.async :as async]
[clojure.string :as string]
[clojure.data.json :as json])
(:import (java.net.http HttpResponse$BodyHandlers HttpRequest HttpClient HttpResponse HttpHeaders HttpRequest$BodyPublishers)
(java.net URI)
(java.util.function Function BiPredicate)
(java.util Optional)))
@souenzzo
souenzzo / pathom.clj
Created Jan 10, 2020
pathom vs select-keys
View pathom.clj
(let [parser (p/parser {::p/plugins [(pc/connect-plugin {::pc/register [(pc/constantly-resolver ::f 42)]})]})
env {::p/reader [p/map-reader
pc/reader2]}
query [::f]
m {::f 42}]
(doseq [[k v] {:map-select #(p/map-select m query)
:parser #(parser env query)
:select-keys #(select-keys env query)}]
(prn k)
(dotimes [i 5]
@souenzzo
souenzzo / pr.clj
Created Nov 20, 2019
Run with "clj -A:dev -m user.pr" or "clj -A:pr"
View pr.clj
(ns user.pr
(:require [cognitect.aws.client.api :as aws]
[clj-http.client :as http]
[clojure.java.io :as io])
(:import (org.eclipse.jgit.api Git)))
(defn slack->request
[text]
{:method :post
:url "https://hooks.slack.com/services/XX/YY/ZZ"
@souenzzo
souenzzo / find-unused-deps.clj
Created Nov 4, 2019
!!!! QUCK'n'DIRTY SOLUTION !!!!
View find-unused-deps.clj
(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\:"
View xf.clj
(let [atributo->item {:a {:atributo :a
:selecionado? true}
:b {:atributo :b
:selecionado? false}
:c {:atributo :c}}]
{:reduce (reduce-kv (fn [acc k {:keys [selecionado?]}]
(if (false? selecionado?)
acc
(conj acc k)))
#{}
You can’t perform that action at this time.