Skip to content

Instantly share code, notes, and snippets.

View dontlaugh's full-sized avatar

Coleman McFarland dontlaugh

View GitHub Profile
@dontlaugh
dontlaugh / markdown_style.md
Last active January 5, 2024 16:58
Coleman's Markdown Style Guide

This guide has moved.


Overview

This guide is for people who deal with software: programmers, sysadmins, etc.

Hard Wrapping

@dontlaugh
dontlaugh / main.go
Created May 17, 2021 21:57
Faktory worker
package main
import (
"context"
"log"
"os"
worker "github.com/contribsys/faktory_worker_go"
)
@dontlaugh
dontlaugh / secrets.py
Created February 23, 2021 18:56
Bitwarden CLI wrapper
#!/usr/bin/env python3
import json
import os
import subprocess
import sys
from subprocess import PIPE
def bw_status():
result = subprocess.run(['bw', 'status'], env=os.environ, stdout=PIPE, check=True)
@dontlaugh
dontlaugh / hate_gitops.md
Created January 5, 2021 19:36
I don't like GitOps

Config attributes (the IP addresses, the names, the values) belong in databases, and git is a bad database.

I like the traditional config management system approach to this. You can start by checking in your infra attributes in git (perhaps in an inventory file), but as you scale, you outgrow this approach and move to querying APIs: from your cloud provider or a config database.

As for secrets, a database is way better for management and security. And yeah, I know you can encrypt and check things into git, but that just moves the ball. Where do you store the encryption keys? You need a centralized solution.

If a git-style interface was a good database for this kind of data, we all would have switched years ago.

Technically, gitops "solves" all these problems, because if (big if here) someone has written a custom controller that does what you need it to do, you can check in a zillion lines of yaml to solve your problem.

@dontlaugh
dontlaugh / update-checker.yaml
Last active August 27, 2020 17:18
Data auditing cron job (update-checker)
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: update-checker
namespace: apis
annotations:
fluxcd.io/automated: "true"
fluxcd.io/tag.update-checker: glob:sha-*
spec:
# Every 6 hours
@dontlaugh
dontlaugh / runbook.md
Created August 26, 2020 20:32
What's a runbook?

What's a Runbook?

A runbook is a precise list of steps for doing routine tasks, or debugging a system.

Good candidates for runbooks:

  • procedures with a relatively precise begin state and end state
  • lists of commands for launching a kubernetes cluster
  • lists of commands for tearing down a kubernetes cluster
  • links to dashboards for troubleshooting problems with a particular system,
@dontlaugh
dontlaugh / generate.go
Created August 14, 2020 15:40
generate random ipv4 address in go
func randomIPFromRange(cidr string) (net.IP, error) {
GENERATE:
ip, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
return nil, err
}
@dontlaugh
dontlaugh / getters.ts
Created August 9, 2020 17:13
Abstract static getters w/o implementation?
abstract class Vpc {
static VpcAlias: string;
// Static getters require a default implementation, so we provide one
// that throws an error. This enforces our subclass overriding.
static get PublicSubnets(): string[] { Vpc.unimplemented("PublicSubnets"); return [""] };
static get PrivateSubnets(): string[] { Vpc.unimplemented("PrivateSubnets"); return [""] };
public static get Subnets(): string[] {
return [...Vpc.PublicSubnets, ...Vpc.PrivateSubnets];
}
@dontlaugh
dontlaugh / networks.ts
Last active August 6, 2020 16:57
Deno AWS cli example
#!/usr/bin/env -S deno run --allow-read --allow-net --allow-run
/*
This script prints out a list of VPCs, subnets, and route tables.
The output will be different depending on which AWS account you are
connected to.
*/
const {stdout, copy} = Deno;
import iro, {
bold, red, dim, yellow, white, blue, cyan, green
From 8/4/2020, 3:32:06 PM to 8/4/2020, 3:35:28 PM
2020-08-04T19:32:06.139381959Z
2020-08-04T19:32:06.139431798Z > novelcovid-api@1.0.1 start:scraper /home/container
2020-08-04T19:32:06.139436761Z > node serverScraper.js
2020-08-04T19:32:06.139439244Z
2020-08-04T19:32:06.85437932Z {
2020-08-04T19:32:06.854403359Z message: '[2020-08-04T19:32:06.851Z] ERROR: Failed to load environment variables',
2020-08-04T19:32:06.854407177Z error: "ENOENT: no such file or directory, open '/home/container/.env'",
2020-08-04T19:32:06.854409963Z stack: "Error: ENOENT: no such file or directory, open '/home/container/.env'\n" +
2020-08-04T19:32:06.854413012Z ' at Object.openSync (fs.js:465:3)\n' +