Skip to content

Instantly share code, notes, and snippets.

Jason Whitlark jwhitlark

  • United States
Block or report user

Report or block jwhitlark

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jwhitlark
jwhitlark / k8s-client.clj
Created Apr 30, 2019
Access Kubernetes API from inside a pod with clojure, clj-http, and a custom ca.crt, with help from aphyr's less-awful-ssl
View k8s-client.clj
;; 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 Feb 28, 2019
Autoclone ...xyz/$GITUSER/$GITREPO into the current directory, when direnv is installed.
View .envrc
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 Jan 31, 2019 — forked from arohner/google-api.clj
Clojure example of accessing google APIs directly
View google-api.clj
(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 Mar 14, 2016 — forked from allgress/reagent_datascript.cljs
Test use of DataScript for state management of Reagent views.
View reagent_datascript.cljs
(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 Mar 25, 2015
Combine friend, oauth2, and JWT token processing.
View google.clj
(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 Jun 20, 2014
Scrubbing Ints: Second attempt
View gist:707f9fb5b379b39c51a5
(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)})
View gist:df071d0f065d9692031e
(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 Jun 20, 2014
Scrubbing ints: first attempt
View gist:0081c0b479591ce1b3c7
(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
View gist:9b99e6448067e35f79b9
(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)))
View gist:5831b282ecce8e15d1e6
(defn clock-view [app owner]
(reify
om/IWillMount
(will-mount [_]
(js/setInterval
(fn [] (om/transact! app :time (fn [_] (js/Date.))))
100))
om/IRender
(render [_]
(dom/div nil (. (:time app) toUTCString)))))
You can’t perform that action at this time.