Skip to content

Instantly share code, notes, and snippets.

View coryodaniel's full-sized avatar
☘️
O'Internets

Cory O'Daniel coryodaniel

☘️
O'Internets
View GitHub Profile
@coryodaniel
coryodaniel / hello-world-pod-2.yaml
Last active July 16, 2021 03:07
Newbernetes hello world pod (sh/http)
apiVersion: v1
kind: Pod
metadata:
name: hello-world-pod-2
labels: # You'll use labels A LOT w/ kube
app: hello-world # They are useful for organizing and identifying attributes of an object
spec:
containers: # This spec has multiple containers, how fancy!
- name: hello-world-sh
image: busybox
@coryodaniel
coryodaniel / job.yaml
Created June 16, 2017 21:08
Perl Pi Job Kubernetes
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
metadata:
name: pi
spec:
containers:
@coryodaniel
coryodaniel / k8s_client.ex
Last active June 15, 2021 13:37
An extremely naive k8s http client
defmodule K8s.Client do
@moduledoc """
This is a very naive k8s client.
"""
alias K8s.Conf.RequestOptions
require Logger
def post(body, conf) do
path = body_to_path(body, false)
url = Path.join(conf.url, path)
@coryodaniel
coryodaniel / docker-compose.yaml
Created October 6, 2020 18:48
Multiple Docker Compose files sharing a network
---
version: "3"
networks:
local-dev:
driver: bridge
---
version: "3"
services:
shell:
image: busybox
@coryodaniel
coryodaniel / find-no-match.sh
Created August 28, 2020 17:45
Shell script to find "no match of right hand side" in elixir
#! /usr/bin/env bash
# This uses the silver searcher (ag)
TMP_FILE=$(mktemp)
# find :ok tuples w/ no error match
ag "^\s{0,}\{:ok.*\s=" --ignore 'test' -G '.ex$' . > ${TMP_FILE}
# find :ok left side matches w/ no error handling
ag "^\s{0,}:ok.*=" --ignore 'test' -G '.ex$' . >> ${TMP_FILE}
@coryodaniel
coryodaniel / v_pg_stat_statements_helpers.sql
Created January 20, 2018 01:17
PG Stat Statements helpers
\set common_pct 0.1
\set common_slow 10
\set other_slow 100
CREATE MATERIALIZED VIEW v_pg_stat_statements AS
WITH totals AS (
SELECT sum(calls) as ttl_calls, sum(total_time) as ttl_time
FROM pg_stat_statements
)
SELECT
@coryodaniel
coryodaniel / slack-text-to-emoji.sh
Last active May 28, 2020 20:24
slack-text-to-emoji
# annoy emoji-name your message here
annoy() {
emoji=$1
msg="${@:2}"
figlet -f banner $msg | sed -e"s/#/:$emoji:/g" | sed -e's/ /:blank:/g' | pbcopy
}
@coryodaniel
coryodaniel / tf.Makefile
Last active May 11, 2020 20:24
Terraform makefile
################### Configuration ###################
TF_NAMESPACE := $(shell basename -s .git `git config --get remote.origin.url`)
TF_S3_BUCKET := my-tf-bucket-name
TF_VERSION := 0.10.6
################### Constants ###################
tmpl-for = $(foreach x,$2,$(call $1,$x))
rule-for = $(foreach x,$2,$(eval $(call $1,$x)))
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
@coryodaniel
coryodaniel / terraform-state-demo.files
Last active May 7, 2020 23:25
terraform state move between multiple files demo
==> ./module <==
==> ./module/main.tf <==
variable "msg" {}
resource "null_resource" "goodbye" {
provisioner "local-exec" {
command = "echo ${var.msg}"
}
}
==> ./main.tf <==
@coryodaniel
coryodaniel / find_unused_routes.rb
Last active May 5, 2020 17:28
find unused rails routes
require "action_dispatch"
require "json"
# RIP your CPU if you have a lot of traffic. Check out the parallel gem w/ multiple processes to speed this up.
list_of_url_paths_visited = File.readlines("list_of_url_paths_visited.txt", chomp: true)
# YMMV
# the 2nd or 3rd column will be the path w/ awk
rake_routes_paths = `rake routes | awk '{if ($2 ~ /\\//) {print $2} else if ($3 ~ /\\//) {print $3}}'`.split("\n")