Skip to content

Instantly share code, notes, and snippets.

View devth's full-sized avatar
Hacking on @yetibot

Trevor Hartman devth

Hacking on @yetibot
View GitHub Profile
#!/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,
@devth
devth / jstack
Created December 30, 2015 02:41
2015-12-29 19:41:09
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.25-b02 mixed mode):
"Attach Listener" #11 daemon prio=9 os_prio=31 tid=0x00007f8d4b826800 nid=0x3a0b waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Thread-0" #10 daemon prio=5 os_prio=31 tid=0x00007f8d4e8af800 nid=0x5703 waiting on condition [0x0000700001658000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.flatland.drip.Main.killAfterTimeout(Main.java:38)