Skip to content

Instantly share code, notes, and snippets.

View mauricioszabo's full-sized avatar

Maurício Szabo mauricioszabo

View GitHub Profile
@mauricioszabo
mauricioszabo / Result - JRuby 9.4.8.0
Last active October 23, 2024 00:20
"Parallel Ruby" example
user system total real
Direct Result 3.250000 0.260000 3.510000 ( 3.255143)
Threads Result 13.980000 0.040000 14.020000 ( 1.773047)
@mauricioszabo
mauricioszabo / monads.clj
Last active June 15, 2023 14:46
Monads with Clojure
(ns monads)
(defn- ensure-instance [class val constructor]
(if (instance? class val)
val
(constructor val)))
(defprotocol IMonad
(bind [this f]))
@mauricioszabo
mauricioszabo / bb-optimized.clj
Last active October 21, 2022 13:58
BB Benchmarks
(ns binarytrees)
(defn bottom-up-tree [item depth]
(if (> depth 0)
[(bottom-up-tree (dec (* 2 item)) (dec depth))
(bottom-up-tree (* 2 item) (dec depth))
item]
[nil nil item]))
(defn item-check [i]
@mauricioszabo
mauricioszabo / with_code.clj
Last active April 18, 2022 04:25
Open Socket REPL on CLR or Clojerl
#Clojerl
./bin/clje \
-e "(do (require 'clojure.core.server) \
(clojure.core.server/start-server \
{:name \"socket-repl\" \
:port 4444 \
:accept 'clojure.main/repl \
:address \"localhost\"}))" -r
#CLR
@mauricioszabo
mauricioszabo / core.clj
Last active March 14, 2022 16:30
Test GraphQL + Pathom3
(ns graphql-test.core
(:require [malli.core :as m]
[clojure.string :as str]
[com.wsscode.misc.coll :as coll]
[com.wsscode.pathom3.interface.eql :as p.eql]
[com.wsscode.pathom3.connect.operation :as connect]
[com.wsscode.pathom3.connect.indexes :as indexes]
[com.walmartlabs.lacinia :as lacinia]
[com.walmartlabs.lacinia.util :as lacinia-util]
[edn-query-language.core :as eql]
@mauricioszabo
mauricioszabo / scripts.sh
Created August 31, 2021 17:44
Squash and lost history
╰─>$ git checkout -b feature-branch
Switched to a new branch 'feature-branch'
╰─>$ git commit -a -m 'Commit 2'
[feature-branch 1f16b96] Commit 2
1 file changed, 1 insertion(+)
╰─>$ git commit -a -m 'Commit 3'
[feature-branch f7c9f08] Commit 3
1 file changed, 1 insertion(+)
@mauricioszabo
mauricioszabo / dependencies
Created June 13, 2021 01:29
Parallel Consumer Example
[io.confluent.parallelconsumer/parallel-consumer-core "0.3.0.2"]
[fundingcircle/jackdaw "0.8.0"]
@mauricioszabo
mauricioszabo / chlorine-config.cljs
Created April 13, 2021 12:29
Chlorine Config for custom resolver of goto var definition
(defn- get-resolver-for-keyword [k]
(p/let [{:keys [text]} (editor/get-namespace)
namespace (str/replace text #"(.*?\.).*" "$1")
res (editor/run-feature :eql [{(list :repl/namespaces {:filter namespace})
[:repl/namespace {:namespace/vars [:var/fqn]}]}])
vars (for [{:namespace/keys [vars]} (:repl/namespaces res)
{:var/keys [fqn]} vars]
fqn)
code (str "(->> " (vec vars)
" (filter (fn [r] (-> r :com.wsscode.pathom.connect/output set (contains? " k "))))"
@mauricioszabo
mauricioszabo / chlorine-config.cljs
Last active March 31, 2021 17:42
My Chlorine Config
(defn- wrap-in-tap [code]
(str "(let [value " code
" rr (try (resolve 'requiring-resolve) (catch Throwable _))]"
" (if-let [rs (try (rr 'cognitect.rebl/submit) (catch Throwable _))]"
" (rs '" code " value)"
" (tap> value))"
" value)"))
(defn tap-top-block []
(p/let [block (editor/get-top-block)]
@mauricioszabo
mauricioszabo / neverending.psql
Created January 7, 2021 12:49
PostgreSQL example of recursive queries
INSERT INTO tree (id, parent_id, description)
VALUES
(6, 6, 'Im Recursive');
WITH RECURSIVE parents as (
select id,
description,
parent_id
from tree
where parent_id = 6