Skip to content

Instantly share code, notes, and snippets.

View Quezion's full-sized avatar

Quest Yarbrough Quezion

View GitHub Profile
@Quezion
Quezion / example-portal.clj
Created October 23, 2023 20:47
Implementation of Portal state inspection tool with Mount state management library
(ns example.portal
"Integration of Mount state management library &
Portal, the external browser-based state inspection tool.
see https://github.com/djblue/portal"
(:require [mount.core :refer [defstate]]
[portal.api :as p]))
(defn new-portal! [] (p/open))
(defonce ^:dynamic *portal* nil)
@Quezion
Quezion / io.github.humbleui.ui.wrap-label.clj
Last active April 4, 2023 18:08
HumbleUI Label to automatically break text across lines, see opt :wrap-width
(ns io.github.humbleui.ui.wrap-label
(:require
[clojure.math :as math]
[clojure.string :as str]
[io.github.humbleui.core :as core]
[io.github.humbleui.protocols :as protocols]
[io.github.humbleui.ui.dynamic :as dynamic])
(:import
[io.github.humbleui.skija Canvas Font FontMetrics Paint TextLine]
[io.github.humbleui.skija.shaper ShapingOptions]))
@Quezion
Quezion / clojure-only-sort-ns.el
Created March 3, 2022 21:50
Automatically alphabetize Clojure namespace declarations on filesave
(defun clojure-only-sort-ns ()
"Sorts the namespaces of a file on-save, but only for clj/cljs/cljc files"
(interactive)
(when (derived-mode-p 'clojure-mode 'clojurec-mode 'clojurescript-mode)
(clojure-sort-ns)))
(add-hook 'before-save-hook 'clojure-only-sort-ns)
@Quezion
Quezion / cider-eval-last-sexp-in-repl.el
Last active February 12, 2022 01:19
Make cider-eval-last-sexp C-x C-e output to REPL buffer
;; Makes Emacs do Cursive's default behavior of inserting & evaling at REPL on C-x C-e
;; Tested on Feb 11 2021 with Emacs 27.2, CIDER 20220125.1326
;; see discussion https://github.com/clojure-emacs/cider/issues/2617
;; taken from WIP commit https://github.com/suvratapte/cider/commit/c177120ff243e032ee6e120e46ac4cccefc07991#diff-3f8317548fccd07e43ee8e69be1b3171
(defun cider-insert-and-eval-last-sexp-in-repl (&rest args)
"Insert the expression preceding point in the REPL buffer and eval."
(interactive)
(cider-insert-last-sexp-in-repl t)
(cider-switch-to-last-clojure-buffer))
@Quezion
Quezion / embedded-nrepl.clj
Last active February 13, 2024 18:17
Embedding an nREPL into a Clojure app that autopicks between CIDER & base handler based on JRK availability
(ns app.nrepl
"Embedding an nREPL into a Clojure app that autopicks between CIDER & base handler based on JDK availability"
(:require
[mount.core :refer [defstate]]
[logger.core :as log]
[slingshot.slingshot :refer [try+ throw+]]
[cider.nrepl :as cider-nrepl]
[nrepl.server :as nrepl]
[clojure.reflect :refer [resolve-class]]
[clojure.set :as set]
;; MELPA (latest)
;; https://www.emacswiki.org/emacs/MELPA
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
'("melpa" . "http://melpa.org/packages/")
t)
(package-initialize))
(ns naming-strategy
(:require
[camel-snake-kebab.core :refer :all]
[clojure.reflect :refer :all]))
; Rough implementation of "naming strategy" feature in Clojure to guarantee consistent names on records
(defn is-camel-case?
[s]
(= s (->camelCase s)))
(ns threading-comparison
(:require
[swiss.arrows :refer [-<> some-<>]]))
(defn schema-from-parameters
"Given a seq of YAML parameter maps (containing string keys 'in' and 'schema'),
returns a hash-map with keys (values of in) and values (values of schema). May return nil.
EX: ({in body schema {...}}
in header schema {...}})
-> {:body {...JSON-SCHEMA...}
(ns memory-storage
"Simple in-memory mocking of traditional RDBMS schema (tables/rows.)"
(:require [swiss.arrows :refer :all]
[com.concur.coreshell.util :as u]))
; Author: Quest Yarbrough
; URL: https://github.com/Quezion
; database is a hashmap with key table names, wrapped in an atom
; tables are a hashmap with key unique IDs
; rows are hashmaps with keys. they should not have IDs already assigned in them.
@Quezion
Quezion / three.cljs
Last active August 29, 2015 14:24 — forked from michiakig/three.cljs
Refactored for current THREE.js and minimized global side-effects
(ns three.demo
(:require
[THREE]))
(defn get-camera []
(let [camera (THREE.PerspectiveCamera. 75 (/ (.-innerWidth js/window)
(.-innerHeight js/window)) 1 10000)]
(set! (.-z (.-position camera)) 1000)
camera))