Skip to content

Instantly share code, notes, and snippets.

View camsaul's full-sized avatar
💭
I am Cam

Cam Saul camsaul

💭
I am Cam
View GitHub Profile
@camsaul
camsaul / x.clj
Created June 3, 2022 17:52
Metabase Query Processor Demo Stuff
(ns metabase.x
(:require [clojure.test :refer :all]
dev.debug-qp
[metabase.models.database :refer [Database]]
[metabase.query-processor :as qp]
[metabase.test :as mt]
[metabase.query-processor.context :as qp.context]
[metabase.query-processor.context.default :as context.default]
[clojure.pprint :as pprint]
[metabase.driver.sql.query-processor :as sql.qp]
@camsaul
camsaul / defenterprise.clj
Last active April 20, 2022 20:12
defenterprise macro PoC
(ns metabase.public-settings.premium-features.defenterprise
(:require [clojure.string :as str]
[metabase.plugins.classloader :as classloader]
[metabase.public-settings.premium-features :as premium-features]
[metabase.util :as u]))
;;; Map of (qualified) function name -> {:oss <oss/fallback fn>
;;; :ee <ee fn>}
(defonce ^:private registry
(atom {}))
@camsaul
camsaul / asm.clj
Created March 10, 2022 23:09
ASM
(ns asm
(:import liquibase.database.core.H2Database
liquibase.database.jvm.JdbcConnection
[org.objectweb.asm Opcodes ClassWriter Type]
[org.objectweb.asm.commons Method GeneratorAdapter]))
(defn x ^ClassWriter []
(let [flags 0
classwriter (org.objectweb.asm.ClassWriter. flags)]
;; define the Class
@camsaul
camsaul / h2.clj
Created February 18, 2022 02:17
Custom Liquibase Table SQL Generator in Clojure
(ns metabase.db.liquibase.h2
"Loading this namespace will replace the default `H2Database` implementation with our custom subclass that uppercases
all identifiers."
(:require [metabase.util :as u]
[clojure.string :as str])
(:import liquibase.database.DatabaseFactory
liquibase.database.jvm.JdbcConnection
liquibase.change.ChangeMetaData
liquibase.change.core.CreateTableChange
liquibase.change.ChangeFactory
@camsaul
camsaul / sparksql_connection_test.clj
Created February 16, 2022 19:27
Tree Shaking the Hive JDBC Driver
(ns metabase.driver.sparksql-connection-test
(:require [clojure.java.jdbc :as jdbc]
[clojure.test :refer :all]))
(deftest connection-test
(println (pr-str (Class/forName "org.apache.hive.jdbc.HiveConnection")))
(is (some? (Class/forName "org.apache.hive.jdbc.HiveConnection")))
(println (pr-str (require 'metabase.driver.hive-like.fixed-hive-connection)))
(is (nil? (require 'metabase.driver.hive-like.fixed-hive-connection)))
@camsaul
camsaul / perms.md
Created February 10, 2022 21:57
MB Download Perms
User has full perms e.g. /download/db/1/ User has perms for all MBQL queries e.g. /download/db/1/schema/ User has perms for a specific Table e.g. /download/db/1/schema/public/table/1/
User can download native results? (/download/db/1/native) yes no no
User can download results for Table 1 (/download/db/1/schema/public/table/1)? yes yes yes
User can download results for Table 2 (/download/db/1/schema/public/table/2)? yes yes no
@camsaul
camsaul / reify_all.clj
Created January 27, 2022 02:53
Reify all/sneaky proxy
;; we have to do a bit of magic to make the [[ConnectionDataSource]] work -- normally if someone were to use it with
;; `with-open` then the original connection would get closed when someone called `.close` on the one from the
;; `DataSource`. So we need to actually have [[ConnectionDataSource]] return a sneaky special proxy Connection that
;; forwards ALL of its other methods to the original Connection EXCEPT for `.close`, which should just no-op.
;;
;; This is all a little hacky for my tastes and it would be better if we could just eliminate [[ConnectionDataSource]]
;; entirely so we didn't need to use this anymore. It's only used in two places anyway.
(defn- reify-all-method [^java.lang.reflect.Method method original-symb]
(let [method-name (-> (symbol (.getName method))
@camsaul
camsaul / profiling.clj
Last active January 13, 2022 00:42
Profiling Results
;; profile everything in a namespace
(doseq [[_ varr] (ns-interns *ns*)] (profile.core/profile-var* varr))
;; run something and get profiling results
(profile.core/profile {} (no-lazyness-test))
@camsaul
camsaul / data.clj
Created August 25, 2021 18:15
Metabase data permissions graph spec
(ns metabase.models.permissions.graph.data
(:require [clojure.spec.alpha :as s]))
(s/def ::id
(s/and int? pos?))
(s/def :metabase.models.permissions.graph.data.table/read
#{:all :none})
(s/def :metabase.models.permissions.graph.data.table/query
@camsaul
camsaul / x.md
Created August 20, 2021 09:57
WSL Emacs 4k

image