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

@camsaul
camsaul / weston.log
Last active August 19, 2021 03:35
weston.log
Date: 2021-08-18 PDT
[18:42:58.437] weston 9.0.0
https://wayland.freedesktop.org
Bug reports to: https://gitlab.freedesktop.org/wayland/weston/issues/
Build: 9.0.0-38-g46756d0e
[18:42:58.438] Command line: /usr/bin/weston --backend=rdp-backend.so --xwayland --shell=rdprail-shell.so --logger-scopes=log,rdp-backend,rdprail-shell --log=/mnt/wslg/weston.log
[18:42:58.438] OS: Linux, 5.10.43.3-microsoft-standard-WSL2, #1 SMP Wed Jun 16 23:47:55 UTC 2021, x86_64
[18:42:58.438] Using config file '/home/wslg/.config/weston.ini'
[18:42:58.439] Output repaint window is 7 ms maximum.
[18:42:58.439] Loading module '/usr/lib/libweston-9/rdp-backend.so'
@camsaul
camsaul / yes-it-is.md
Created August 16, 2021 23:57
Markdown test

Yes, it is

@camsaul
camsaul / deps.edn
Created June 21, 2021 20:48
Tree example
{:deps {org.clojure/tools.deps.alpha {:mvn/version "0.11.931"}
clj-http/clj-http {:mvn/version "3.10.3"}}}