Skip to content

Instantly share code, notes, and snippets.

@adamf
adamf / extra_logging.py
Created March 24, 2023 16:42
Add datadog span & event information to structured logs in a Django app
import logging
from typing import Any, Dict
import ddtrace
from ddtrace import tracer
def datadog_context(
logger: logging.Logger, log_method: Any, event_dict: Dict[Any, Any]
) -> Dict[Any, Any]:
@adamf
adamf / make_gcp-aws_ha_vpn.sh
Last active January 9, 2023 20:28
Bash script to create an HA VPN between GCP and AWS.
#!/bin/bash
set -exu -o pipefail
# This script creates a highly-available VPN between a VPC in Google Cloud Platform
# and a VPC in AWS. This does all of the work (and a bit more) detailed in
# https://cloud.google.com/architecture/build-ha-vpn-connections-google-cloud-aws
export AWS_PAGER=""
@adamf
adamf / run_minikube.sh
Created August 5, 2020 18:35
Running minikube + tilt ci in a github action
#!/bin/bash
set -exu
PLATFORM=$(uname)
# If the minikube cluster doesn't exist, the return code is 7
# we'll test this later to see if we need to do a bunch of initial setup on
# services (eg, create RBAC for k8s, create DB users, etc)
MINIKUBE_STATUS_GREP_NON_EXISTENT=0
$ helm template q /Users/adamf/Source/Q/services/webapp/django-core-chart --set otherGlobalLabels.bar=foo
---
# Source: django-core-chart/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: q-django-core-chart
labels:
helm.sh/chart: django-core-chart-0.1.0
$ helm template q /Users/adamf/Source/Q/services/webapp/django-core-chart --set otherGlobalLabels.bar=foo
---
# Source: django-core-chart/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: q-django-core-chart
labels:
helm.sh/chart: django-core-chart-0.1.0
@adamf
adamf / generated_service.yaml
Last active February 7, 2020 17:37
Helm example chart testing
$ helm template q /Users/adamf/Source/Q/services/example-service/example-service-chart --set q-example-service-chart.metadata.metadata.labels.f=ff --set example-service-chart.labels.foo=bar
---
# Source: example-service-chart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: q-example-service-chart
labels:
app.kubernetes.io/name: example-service-chart
helm.sh/chart: example-service-chart-0.1.0
df = pd.read_csv("example.csv", parse_dates=True, infer_datetime_format=True)
df.starttime = pd.to_datetime(arg=df.starttime, infer_datetime_format=True)
df.index = pd.DatetimeIndex(df.starttime)
df['date_only'] = df.index.floor('1D')
df['2018-08-01':'2018-08-03'].groupby(['name','date_only','event_id']).event_count.sum()
start_date = datetime.date(2018, 8, 30)
df[start_date - pd.DateOffset(days=10):start_date].groupby(['name','date_only','event_id','event_sub_id']).event_count.sum()
df[start_date - pd.DateOffset(days=10):start_date].groupby(['name','date_only','event_id']).event_count.sum()[:10].to_csv()
@adamf
adamf / buggy_sf2.lua
Created November 7, 2017 17:24
Lua code to read player data from StreetFighter II Turbo for SNES via BizHawk's Lua environment. Contains some bugs!
json = require "json"
function get_framecount()
return emu.framecount()
end
function get_p1_health()
return mainmemory.read_u8(0x000530)
end
machine:
xcode:
version: 8.3
dependencies:
override:
- source bin/setup_dev_env.sh
compile:
override:
import csv
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--field', help='field number to output')
parser.add_argument('--filename', help='filename to parse')
args = parser.parse_args()
with open(args.filename) as csvfile:
fields = csv.reader(csvfile)