Skip to content

Instantly share code, notes, and snippets.

View devth's full-sized avatar
Deep Work

Trevor Hartman devth

Deep Work
View GitHub Profile
@devth
devth / spec.cljs
Last active February 21, 2017 00:16 — forked from swannodette/spec.cljs
om.next query spec
(ns om.next.spec
(:require [cljs.spec :as s]))
(s/def ::ident (s/and vector? (s/cat :ident keyword? :value #(not (coll? %)))))
(s/def ::join-key (s/or :prop keyword? :ident ::ident))
(s/def ::join (s/map-of ::join-key ::query))
(s/def ::union (s/map-of keyword? (s/map-of keyword? ::query)))
(s/def ::param-expr
#!/usr/bin/env bash
if [[ "$1" == '-h' ]] || [[ $# != 1 ]]; then
echo "Usage: $(basename "$0") <nodepool>"
echo
echo "<nodepool> can be a partial match to grep for, e.g. '2016-08-19'"
echo
echo "NOTE: Before draining all nodes in the old pool should be cordoned!"
exit 1;
fi
kubectl --namespace kube-system get pod -l k8s-app=kube-dns -oname | \
xargs -I% -n1 sh -c 'echo %; kubectl --namespace kube-system -ckubedns logs %; echo'
(reduce
(fn [acc i]
(update-in
acc [i]
(fn [x y] (prn x y) (+ y (or x 0)))
(* 2 i)))
{}
[1 2 3 4 1])
use std::fs;
use std::io;
use std::path::PathBuf;
fn main() {
let dir = env!("DIR").to_string();
println!("Looking in {}", dir);
let _ = loop_dir_contents(&dir);
}
@devth
devth / install_kubectl.sh
Last active May 19, 2016 20:06
Obtain metadata in pods
# Useful for installing kubectl in a docker image
curl -L -O https://storage.googleapis.com/kubernetes-release/release/v1.2.4/bin/linux/amd64/kubectl
# obtain the node name inside a pod
KUBERNETES_NODENAME=`kubectl get pods --namespace=${KUBERNETES_NAMESPACE} ${KUBERNETES_PODNAME} -o json | jq -r .spec.nodeName`
val cost: Option[String] = Some("123")
val method: Option[String] = None
(cost, method) match {
case (Some(c), Some(m)) => Some(s"$c $m")
case (Some(c), None) => Some(s"$c")
case (None, Some(m)) => Some(s"$m")
case _ => None
}
object HouseBuilderAsync1 {
def circumference(d: Double): Future[Double] = Math.piSlow.map { _ * d }
def buildWindow(c: Double): Window = Window(c)
def buildHouse(window: Window): House = House(window)
}
object HouseControllerAsync1 {
import HouseBuilderAsync._
circumference(10).map(buildWindow).map(buildHouse)
// scala.concurrent.Future[AsynsVsSync.House] = Success(House(Window(31.400000000000002)))
}
(defn- ensure-min-vec-size [v size]
"Ensure v has at least size elements. Fill with `nil` if necessary."
(let [d (- size (count v))]
(if (> d 0) (into v (vec (repeat d nil))) v)))
(defn- find-or-create
"Build up nested path with possibly-numeric indices as vectors and other keys
as maps"
[m [k1 k2 & path]]
(let [ds (cond-> (get-in m [k1] (if (number? k2) (vec (repeat k2 nil)) {}))
lazy val root = (project in file(".")).
settings(
name := "compiled-query",
version := "1.0",
scalaVersion := "2.11.7",
resolvers += "Sonatype OSS Snapshots" at
"https://oss.sonatype.org/content/repositories/snapshots",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,