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 / deps_graph.clj
Last active May 8, 2024 02:35
Load Clojure namespace dependency graph into a Postgres database
(ns metabase.deps-graph
(:require
[clojure.tools.namespace.dependency :as ns.deps]
[clojure.tools.namespace.find :as ns.find]
[clojure.tools.namespace.parse :as ns.parse]
[clojure.java.io :as io]))
(set! *warn-on-reflection* true)
(defn- find-ns-decls []
@camsaul
camsaul / hello_world.asm
Last active April 30, 2024 11:16
Hello World in NES (6502 / NESASM) Assembly. Display a single sprite
;;; -*- tab-width: 2 -*-
;;; These four lines go at the beginning of almost every code file. 16-byte iNES header
.inesprg 1 ; one bank of program code
.ineschr 1 ; one bank of picture data
.inesmap 0 ; we use mapper 0
.inesmir 1 ; Mirror setting always 1
;;; BANKING
@camsaul
camsaul / avg.cljc
Last active April 12, 2024 19:41
One namespace with everything related to a clause??
(ns metabase.lib.clause.avg
(:require
;; I think we should probably actually introduce some sort of interface namespace with all the relevant `defmulti`
;; methods a clause would need to implement so we don't need to `:require` so many different namespaces. Then it's
;; also clear at a glance what sorts of things you can/need to implement for a clause.
[metabase.legacy-mbql.normalize :as mbql.normalize]
[metabase.lib.common :as lib.common]
[metabase.lib.convert :as lib.convert]
[metabase.lib.hierarchy :as lib.hierarchy]
[metabase.lib.metadata.calculation :as lib.metadata.calculation]
@camsaul
camsaul / stack_trace.txt
Created April 9, 2024 18:22
Redshift flaky test stacktrace 2
[pool-2-thread-6] ERROR metabase.test.data.impl.get-or-create - Failed to sync test database "airports": Error executing query: ERROR: schema "2024_04_08_2dc86260_fec9_4d76_a0e6_3a3ca771b924_schema" does not exist
clojure.lang.ExceptionInfo: Failed to sync test database "airports": Error executing query: ERROR: schema "2024_04_08_2dc86260_fec9_4d76_a0e6_3a3ca771b924_schema" does not exist
at metabase.test.data.impl.get_or_create$sync_newly_created_database_BANG_.invokeStatic(get_or_create.clj:130) [?:?]
at metabase.test.data.impl.get_or_create$sync_newly_created_database_BANG_.invoke(get_or_create.clj:110) [?:?]
at metabase.test.data.impl.get_or_create$create_database_BANG_.invokeStatic(get_or_create.clj:153) [?:?]
at metabase.test.data.impl.get_or_create$create_database_BANG_.invoke(get_or_create.clj:139) [?:?]
at metabase.test.data.impl.get_or_create$create_database_with_bound_settings_BANG_$thunk__142153.invoke(get_or_create.clj:165) [?:?]
at metabase.test.data.impl.get_or_create$create_database_with
@camsaul
camsaul / stack_trace.txt
Created April 9, 2024 18:15
Flaky Redshift tests stacktrace
[main] ERROR metabase.test.data.impl.get-or-create - Failed to sync test database "test-data": ERROR: relation "odygyrpmbchatyymvtwv.table_with_access" does not exist
clojure.lang.ExceptionInfo: Failed to sync test database "test-data": ERROR: relation "odygyrpmbchatyymvtwv.table_with_access" does not exist
at metabase.test.data.impl.get_or_create$sync_newly_created_database_BANG_.invokeStatic(get_or_create.clj:130) [?:?]
at metabase.test.data.impl.get_or_create$sync_newly_created_database_BANG_.invoke(get_or_create.clj:110) [?:?]
at metabase.test.data.impl.get_or_create$create_database_BANG_.invokeStatic(get_or_create.clj:153) [?:?]
at metabase.test.data.impl.get_or_create$create_database_BANG_.invoke(get_or_create.clj:139) [?:?]
at metabase.test.data.impl.get_or_create$create_database_with_bound_settings_BANG_$thunk__142153.invoke(get_or_create.clj:165) [?:?]
at metabase.test.data.impl.get_or_create$create_database_with_bound_settings_BANG_.invokeStatic(get_or_create.clj:174) [?:?]
at metabase.test.d
@camsaul
camsaul / demo.clj
Created April 4, 2024 16:59
Metadata providers demo
(ns demo
(:require
[metabase.driver :as driver]
[metabase.driver.sql.query-processor :as sql.qp]
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
[metabase.lib.metadata.jvm :as lib.metadata.jvm]
[metabase.lib.test-metadata :as meta]
[metabase.lib.test-util :as lib.tu]
[metabase.query-processor.compile :as qp.compile]
@camsaul
camsaul / dataset_hating_map.clj
Created February 21, 2024 18:08
Dataset Hating Map
;;; it's a map that hates if you try to get the key `:dataset` from it. NOCOMMIT
(declare ->DatasetHatingMap)
(defn- check-for-dataset-key [k]
(when (= k :dataset)
(throw (ex-info ":dataset is deprecated, use :type instead!" {}))))
(p/def-map-type DatasetHatingMap [m]
(get [_this k default-value]
(check-for-dataset-key k)
@camsaul
camsaul / biggest-files.sh
Created March 15, 2024 18:19
Biggest files
#! /usr/bin/env bash
set -euo pipefail
for file in `find . -type f -name '*.clj' -or -name '*.cljc' -or -name '*.cljs'`; do \
wc -l "$file" |
perl -ne 'my @parts = /(^\d+)\s(.*$)/; printf("%05d %s\n", $parts[0], $parts[1]);'
done |
sort -r |
head -n 20
@camsaul
camsaul / kebab_hating_map.clj
Created September 1, 2023 01:29
Kebab Case Key Hating Map
(ns metabase.util.kebab-hating-map
"This is a map type that catches attempts to get `:kebab-case` values from it. In prod, it logs a warning and gets the
value for the equivalent `snake_case` key; in tests and dev it throws an Exception.
This is here so we can catch driver code is still supposed to be using Toucan instances rather than MLv2 Metadata.
This is intended to be only temporary; after everything in the QP is converted to MLv2 we can remove this."
(:require
[clojure.string :as str]
[metabase.config :as config]
[metabase.driver :as driver]
@camsaul
camsaul / snake_hating_map.clj
Created September 1, 2023 01:28
Snake Key Hating Map
(ns metabase.util.snake-hating-map
"This is a map type that catches attempts to get `:snake_case` values from it. In prod, it logs a warning and gets the
value for the equivalent `kebab-case` key; in tests and dev it throws an Exception.
This is here so we can catch driver code that needs to be updated in 48+ to use MLv2 metadata rather than Toucan
instances. After 51 we can remove this, everything should be updated by then."
(:require
[clojure.string :as str]
[metabase.config :as config]
[metabase.driver :as driver]