Skip to content

Instantly share code, notes, and snippets.

View jwhitlark's full-sized avatar

Jason Whitlark jwhitlark

View GitHub Profile
@jwhitlark
jwhitlark / gist:b30882e496d1d60a5aebdcd5a2baeb9a
Last active July 31, 2023 18:29
Find a class from the short name (requires google guava)
(take 10 (filter #(clojure.string/ends-with? % "DefaultChannelPool")
(map str (.getAllClasses (com.google.common.reflect.ClassPath/from
(.getContextClassLoader (Thread/currentThread)))))))
@jwhitlark
jwhitlark / k8s-client.clj
Created April 30, 2019 01:55
Access Kubernetes API from inside a pod with clojure, clj-http, and a custom ca.crt, with help from aphyr's less-awful-ssl
;; less-awful-ssl {:mvn/version "1.0.4"}
;; clj-http {:mvn/version "3.9.1"}
(let [trust-store (less.awful.ssl/trust-store (clojure.java.io/file "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"))
bearer-token (format "Bearer %s" (slurp "/var/run/secrets/kubernetes.io/serviceaccount/token"))
kube-api-host (System/getenv "")
kube-api-port (System/getenv "")]
(clj-http.client/get
(format "https://%s:%s/apis/<something-protected>" kube-api-host kube-api-port)
{:trust-store trust-store
@jwhitlark
jwhitlark / .envrc
Created February 28, 2019 19:17
Autoclone ...xyz/$GITUSER/$GITREPO into the current directory, when direnv is installed.
PARENT=$(basename $PWD)
GRANDPARENT=$(basename $(dirname $PWD))
REPOPATH=$GRANDPARENT/$PARENT
if [ ! -d .git ]; then
echo "Cloning $REPOPATH into $PWD"
tfile=$(mktemp /tmp/envrc.XXXXXXXXX)
mv .envrc $tfile
git clone https://github.com/$REPOPATH.git ./
mv $tfile .envrc
@jwhitlark
jwhitlark / google-api.clj
Created January 31, 2019 19:45 — forked from arohner/google-api.clj
Clojure example of accessing google APIs directly
(ns example.api.google
(:require [cemerick.url :as url]
[cheshire.core :as json]
[clj-jwt.core :as jwt]
[clj-jwt.key :as key]
[clj-time.core :as time]
[clj-http.client :as http]
[clojure.string :as str])
(:import java.io.StringReader))
@jwhitlark
jwhitlark / reagent_datascript.cljs
Created March 14, 2016 22:56 — forked from allgress/reagent_datascript.cljs
Test use of DataScript for state management of Reagent views.
(ns reagent-test.core
(:require [reagent.core :as reagent :refer [atom]]
[datascript :as d]
[cljs-uuid-utils :as uuid]))
(enable-console-print!)
(defn bind
([conn q]
(bind conn q (atom nil)))
@jwhitlark
jwhitlark / google.clj
Created March 25, 2015 20:16
Combine friend, oauth2, and JWT token processing.
(ns foo.auth.google
(:require [clojure.string :as str]
[clojure.java.io :as io]
[clojure.data.json :as json]
[clojure.logging :refer :all]
[friend-oauth2.util :refer [format-config-uri]]
[friend-oauth2.workflow :as oauth2])
(:import [java.security.cert CertificateFactory]
[org.apache.commons.codec.binary Base64]))
@jwhitlark
jwhitlark / gist:707f9fb5b379b39c51a5
Created June 20, 2014 20:45
Scrubbing Ints: Second attempt
(defn scrubbing-int-app-event-view-2 [app owner]
(reify
om/IInitState
(init-state [_]
{:capturing false
:start-x nil})
om/IWillMount
(will-mount [_]
(let [mouse-chan (async/map (fn [e] {:x (.-clientX e)
:type (.-type e)})
@jwhitlark
jwhitlark / gist:df071d0f065d9692031e
Created June 20, 2014 20:35
Lowering the sensitivity
(if (zero? (mod difference 5))
(do (om/update-state! owner :my-val (partial + (/ difference 5)))
(om/set-state! owner :start-x x)))
@jwhitlark
jwhitlark / gist:0081c0b479591ce1b3c7
Created June 20, 2014 20:30
Scrubbing ints: first attempt
(defn scrubbing-int-state-view [app owner]
(let [start-capturing #(do (om/set-state! owner :capturing true)
(om/set-state! owner :start-x (.-clientX %)))
stop-capturing #(do (om/set-state! owner :capturing false)
(om/set-state! owner :start-x nil))]
(reify
om/IInitState
(init-state [_]
{:my-val 0
:capturing false
(defn listen [el & types]
(let [out (chan)]
(doall (map (fn [type] (events/listen el type #(put! out %))) types))
out))
(defn set-states! [owner desired]
(doall (map #(om/set-state! owner (key %) (val %)) desired)))