Skip to content

Instantly share code, notes, and snippets.

@whitlockjc
whitlockjc / rgbaToHex.js
Last active July 18, 2022 10:25
Use JavaScript to Convert RGBA CSS Value to Hexadecimal
#!/usr/bin/env node
// Takes an rgba() CSS value and converts it to its 8 digit hexadecimal value.
//
// Usage: ./rgbaToHex.js "{YOUR_RGBA_STRING}"
//
// Example: ./rgbaToHex.js "rgba(197, 200, 198, .2)" => #C5C8C633
function trim (str) {
return str.replace(/^\s+|\s+$/gm,'');
@whitlockjc
whitlockjc / example.el
Created March 9, 2016 18:25
Emacs linum-format that works around whitespace-mode and padding
;; Linum mode
(global-linum-mode t)
;; Custom face/function to pad the line number in a way that does not conflict with whitespace-mode
(defface linum-padding
`((t :inherit 'linum
:foreground ,(face-attribute 'linum :background nil t)))
"Face for displaying leading zeroes for line numbers in display margin."
:group 'linum)
@whitlockjc
whitlockjc / wordcount.js
Created May 13, 2014 20:23
Node.js Based Wordcount MapReduce Job
'use strict';
var FileInputFormat = require('hadoop-input').FileInputFormat;
var FileOutputFormat = require('hadoop-output').FileOutputFormat;
var counterGroup = 'Word Count Counters';
var uniqueWordCounterName = 'Unique Words';
var totalWordsCounterName = 'Total Words';
var uniqueWordsCounter;
var totalWordsCounter;
@whitlockjc
whitlockjc / Environment_for_Developing_Kubernetes.md
Last active June 15, 2019 18:35
Resources on creating a development environment for contributing to Kubernetes.

Environment for Developing Kubernetes

First and foremost, this is not a document on how to create an environment for developing applications targeting Kubernetes as its runtime. This document is to outline the steps required to create an environment for contributing to Kubernetes based on recently setting up both Linux and Mac development environments. This document is written as if you will be creating your development enivonment on OS X but just know that things are basically the same when on other OSes. Of course, the installation and configuration of these tools will changed based on which OS you're on, and possibly other things, but the gist is that in this guide when you see that tool X is required, you follow whatever steps to install tool X on your OS.

@whitlockjc
whitlockjc / k8s-intra-cluster-router.md
Last active June 22, 2018 04:33
Proof of concept on how to implement an intra-cluster router within Kubernetes.

Overview

Imagine you are an API Management company and your business depends on your ability to be involved in the request/response lifecycle for HTTP-based API traffic. Also imagine that you've got a Kubernetes cluster that runs both your company's applications and even some client applications. This means when it comes to doing API Management for all necessary traffic, you need to be involved in the request/response lifecycle for targets running within Kubernetes for both requests originating outside the cluster and even some (if not all) requests originating within the cluster. To continue this conversation, let's establish some terminology:

  • Inter-Cluster: An external request is made for an API that maps to a resource running within Kubernetes
@whitlockjc
whitlockjc / k8s-namespace-watcher.js
Created May 22, 2017 18:16
Simple Node.js example of how to use a Kubernetes watcher
'use strict';
const fs = require('fs')
const http = require('http')
const K8S_HOST = process.env['K8S_HOST'] || '10.100.0.1'
const K8S_SECRET = process.env['K8S_SECRET'] ||
fs.readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/token', 'utf-8')
var req = http.request({
@whitlockjc
whitlockjc / Useful_kubectl_Commands.md
Last active February 13, 2017 18:40
Useful kubectl commands

Useful kubectl commands not in the kubectl Cheat Sheet:

List all nodes and their external IP

kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.addresses[?(@.type=="ExternalIP")].address}{"\n"}{end}'

List all running Pods and their IP

kubectl get pods --all-namespaces -o jsonpath='{range .items[?(@.status.phase=="Running")]}{.metadata.name}{"\t"}{.status.podIP}{"\n"}{end}'

@whitlockjc
whitlockjc / local-up-cluster.sh.diff
Last active January 10, 2017 05:06
Work in progress to get "hack/local-up-cluster.sh" working with a Dockerized "kubelet" on Docker for Mac.
diff --git a/hack/local-up-cluster.sh b/hack/local-up-cluster.sh
index 92b13eab89..9a85c463c5 100755
--- a/hack/local-up-cluster.sh
+++ b/hack/local-up-cluster.sh
@@ -22,12 +22,14 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
DOCKER_OPTS=${DOCKER_OPTS:-""}
DOCKER=(docker ${DOCKER_OPTS})
DOCKERIZE_KUBELET=${DOCKERIZE_KUBELET:-""}
+DOCKERIZED_KUBELET_IMAGE=${DOCKERIZED_KUBELET_IMAGE:-"gcr.io/google_containers/kubelet:local-up-cluster"}
ALLOW_PRIVILEGED=${ALLOW_PRIVILEGED:-""}
@whitlockjc
whitlockjc / Kubernetes_Authentication_With_UAA.md
Last active August 18, 2016 22:34
Proof of a post I'm writing for the Apigee blog on using CloudFoundry's UAA for Kubernetes authentication via OIDC.

Kubernetes Authentication with UAA

Recently at Apigee we have started using [Kubernetes][kubernetes] and while working on securing access to it, we learned a few things that we felt could be useful to other Kubernetes consumers. This post will discuss how we were able to use CloudFoundry's [UAA][uaa] as an [OpenID Connect Provider][oidc] for Kubernetes authentication. If you are not using UAA but you are using an [OAuth2][oauth2] provider for your authentication needs, stick around because this post could be useful to you as well.

Note: This post provides background on the process we took and how we successfully wired things up. If you do not care about this and just want to know the steps required to use UAA, and possibly other OAuth 2.0 providers, as an OIDC

@whitlockjc
whitlockjc / DevelopingAgainstKubernetesOnOSX.md
Last active July 26, 2016 23:39
Developing Against Kubernetes on OS X

When developing against/for Kubernetes, there are two major technologies that you need to have setup:

  • [Docker][docker]
  • [Kubernetes][kubernetes]

I have what I believe to be a very, very simple local development setup using these two technologies that I want to share with you. That being said, let's get started.

Prerequisites