Skip to content

Instantly share code, notes, and snippets.

@phntom
phntom / ci.Dockerfile
Created September 16, 2025 09:08
CircleCI cimg/base:2025.09-24.04 with gcloud kubectl helm sops jq and docker
# docker buildx build -t docker.io/phntom/stdf-ci:2025.09-24.04-1 --platform linux/amd64,linux/arm64 --pull --push -f ci.Dockerfile .
# Base image
FROM cimg/base:2025.09-24.04
# Install gcloud, kubectl, helm, sops, jq, and docker
# Install sops
COPY --from=ghcr.io/getsops/sops:v3.10.2 /usr/local/bin/sops /usr/local/bin/sops
COPY --from=alpine/helm:3.19 /usr/bin/helm /usr/bin/helm
@phntom
phntom / gist:5da45fd910240113c540737fe5907fb8
Created July 13, 2021 13:36
how to log oauth2-proxy using ingress-nginx X-Auth-Request-Email X-Auth-Request-User Authorization log-format-upstream
ingress-nginx.controller.config.log-format-upstream:
log-format-upstream: '{"time": "$time_iso8601", ... "remote_user": "$remote_email"...
kube-prometheus-stack.grafana.ingress.annotations:
nginx.ingress.kubernetes.io/auth-response-headers: X-Auth-Request-Email
nginx.ingress.kubernetes.io/configuration-snippet: |
auth_request_set $remote_email $upstream_http_x_auth_request_email;
add_header X-Auth-Request-Email $remote_email;
def ed(w1, w2):
l1, l2 = len(w1), len(w2)
if l1 == 0:
return l2
if l2 == 0:
return l1
prefix1, last1 = w1[:-1], w1[-1:]
prefix2, last2 = w2[:-1], w2[-1:]
class RandomLinkedList(object):
def __init__(self, data, p_next, p_rnd):
self.data = data
self.p_next = p_next
self.p_rnd = p_rnd
five = RandomLinkedList(5, None, None)
four = RandomLinkedList(4, five, None)
three = RandomLinkedList(3, four, five)
four.p_rnd = three
def count_stepping_numbers(n1, n2):
assert n1 > 0 and n2 > 0
assert n2 > n1
f1 = lambda n: n >= n1
ln1 = len(str(n1))
f2 = lambda n: n <= n2
ln2 = len(str(n2))
fs = {ln1: lambda x: f1(x) and f2(x)} if ln1 == ln2 else {ln1: f1, ln2: f2}
s = 0
numbers = {
78279277: 'STARWARS'
}
words = set(numbers.values())
mapping = {
'2': 'ABC',
'3': 'DEF',
'4': 'GHI',
### NaiveMultiCoinSum ###
# this is O(2^n) runtime and O(n) space
def coin_sum(coins, target_sum):
# the number of coins combinations that sum to target
seen_ordered = set()
seen_unordered = set()
coin_sum_aux(coins, target_sum, [], seen_ordered, seen_unordered)
return len(seen_ordered), len(seen_unordered)
def coin_sum_aux(coins, remainder, current_pick, seen_o, seen_u):
def lowest_common_ancestor(root, n1, n2):
if n1 > n2:
n1, n2 = n2, n1
if n1 <= root and not n2 <= root:
# this is a split point
return root
if n1 <= root:
# go left
return lowest_common_ancestor(root.left, n1, n2)
else:
def count_neg_sorted_matrix(m):
count = 0
row = 0
rows = len(m)
cols = len(m[row])
for col in reversed(range(cols)):
# range(n) = [0, 1, ... n-1]
while m[row][col] < 0:
count += (col + 1)
def find_max_subsequence_naive(seq):
assert all(isinstance(x, int) for x in seq)
# this is O(n^3) iirc
f = 0
l = len(seq)
m = sum(seq)
for i in xrange(len(seq)):
for j in xrange(i + 1, len(seq) + 1):
n = sum(seq[i:j])
if n > m: