Skip to content

Instantly share code, notes, and snippets.

@pmorelli92
Last active April 7, 2023 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmorelli92/8f28fda67396a49a6c46b0964be4f5a8 to your computer and use it in GitHub Desktop.
Save pmorelli92/8f28fda67396a49a6c46b0964be4f5a8 to your computer and use it in GitHub Desktop.
Knowledge base

Knowledge base

All interesting links and reflections throughout time goes here.

Cheat Sheet

Postgres UUID

create extension "uuid-ossp";
select uuid_generate_v4();

Postgres UPDATE FROM SELECT

UPDATE
    Table_A
SET
    Table_A.col1 = Table_B.col1
FROM
    Some_Table AS Table_A
WHERE
    Table_A.col3 = 'cool'

Create new table from existing

alter table tablename rename to oldtable;
create table tablename (column defs go here);
insert into tablename (col1, col2, col3) select col2, col1, col3 from oldtable;
alter table tablename OWNER TO someownerifneeded;

Replace text on file using sed

sed -i '' 's/old/new/g' /path/to/file.txt

Git replace master with our branch

git checkout seotweaks
git merge -s ours master
git checkout master
git merge seotweaks

Git update submodules

git submodule foreach git pull origin master

Git update fork

git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
git pull upstream master

Git copy code from VSTS to GitHub (or others)

git clone --mirror <url_of_old_repo>
cd <name_of_old_repo>
git remote add new-origin <url_of_new_repo>
git push new-origin --mirror
git remote rm new-origin

Kubernetes delete evicted pods

kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod

Flux Sync

alias ff='fluxctl sync --k8s-fwd-ns flux'

Flux Helm Sync

kb exec -n flux helm-operator-5f85794486-xq59m -- curl -XPOST http://localhost:3030/api/v1/sync-git

Go dependencies graph

godepgraph -nostdlib -horizontal -onlyprefixes=github.com/repo/svc github.com/repo/svc/cmd/server | dot -Tpng -o godepgraphz.png

Links

General

C#

  • Use class for identity and behaviour (DDD).
  • Use struct for value objects without behaviour (such as Money).
  • The record keyword adds IEquatable and ToString comparators.
  • A record class is inmmutable, you can create copies with the with keyword.
  • A record struct is mutable unless you add the readonly keyword.

Golang

Postgres

Github Pages

Kubernetes

Kubernetes Summary

  • Health check: Restarts pod if it does not work, so just check the internal dependencies, that can be solved with a restart, are up.
  • Ready check: Stop routing traffic if it does not work, check external dependencies, now beware you can actually give cause latency issues or denial of service to yourself, be conservative.
  • Cluster autoscaling: Feature of GKE, add more nodes workers to certain node pool.
  • Horizontal scale: Upon certain metric (could be custom or could be cpu/mem) reaches a % another replica could be spawned.
  • Vertical scale:
    • Has 2 modes, recommendation and update. Possibility of excluding certain container of a pod.
    • On recommendation it tells you how much mem/cpu you need to assign as resource.
    • On auto it kills the pod and spawns a new one with new resource.
    • Does not work on auto when only 1 replica.
    • Pdb is recommended so you don't have downtime.
  • Goldilocks:
    • Tool that exposes dashboard and fires vpa for every container on namespace.
    • Dashboard allows you to port forward and check the recommended limits, so you change yourself.
  • Resources:
    • Requests: The minimum the scheduler needs to allocate for running this container.
    • Limits: Pod can reach up to this amount, in an overcommited state (likely to be killed).
    • cpu: 50m is expressed in millicores, 1000 is 1 cpu, 250 1/4 cpu. In case of overcommitted it will get throttled.
    • memory: Expressed in Mi as memybytes. In case of overcommitted it will get killed.

Istio

BankID

Signicat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment