Skip to content

Instantly share code, notes, and snippets.

View ptrkrlsrd's full-sized avatar

Petter K ptrkrlsrd

  • Studied @ NTNU // Works for Boitano
  • Norway
  • 12:51 (UTC +02:00)
View GitHub Profile
@ptrkrlsrd
ptrkrlsrd / ApplicationInsightsExtensions.cs
Created June 8, 2023 13:51
ApplicationInsightsExtensions.cs
using Microsoft.ApplicationInsights;
namespace <namespace>;
public static class ApplicationInsightsExtensions
{
public static void TrackEvent(this TelemetryClient client, string eventName, IEnumerable<(string, string)> metadataTuples)
{
Dictionary<string, string> metadata = Dictionary(metadataTuples);
client.TrackEvent(eventName, metadata);
#[derive(Debug)]
pub enum Err {
JSONError(serde_json::Error),
HTTPError(reqwest::Error),
}
macro_rules! convert_error {
($a:ty, $b:ident, $c:expr) => {
impl From<$a> for $b {
@ptrkrlsrd
ptrkrlsrd / test.cs
Created November 2, 2021 09:39
Test your services controllers for verbs to avoid bad practice in naming API endoints
[Fact]
public void RouteShouldNotHaveVerbs()
{
var service = _server.Host.Services.GetService(typeof(IActionDescriptorCollectionProvider)) as IActionDescriptorCollectionProvider;
Assert.NotNull(service);
string[] verbs = { "create", "get", "post", "put", "delete", "fetch", "generate" };
Regex rx = new Regex($"({string.Join("|", verbs)})", RegexOptions.Compiled | RegexOptions.IgnoreCase);
version: '3.6'
services:
postgres:
image: postgres:12
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgrespassword
graphql-engine:
worker_processes auto;
events {
worker_connections 1024;
}
http {
server_tokens off;
charset utf-8;
def main():
pass
if __name__ == "__main__":
main()
@ptrkrlsrd
ptrkrlsrd / Dockerfile.go
Last active August 22, 2021 13:34
Dockerfile for Go
FROM golang:1.16.5 AS build-stage
WORKDIR /app
COPY go.mod .
COPY . .
RUN go get
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
FROM alpine:3.14 as run-stage
RUN apk add ca-certificates
version: "3.9" # optional since v1.27.0
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
- logvolume01:/var/log
links:
@ptrkrlsrd
ptrkrlsrd / remove_evicted.sh
Created March 31, 2021 13:12
remove_evicted.sh
evictedPods=$(kubectl get pods --all-namespaces | grep 'Evicted' | \
awk 'IF $6 ~ /h|d/ {print $1 "|" $2}')
# Loop through evicted pods and delete them
for pod in $evictedPods; do
IFS='|' read namespace evictedPod <<< "$pod";
kubectl -n $namespace delete pod $evictedPod;
echo $evictedPod;
sleep 0.25
done
@ptrkrlsrd
ptrkrlsrd / export-kubernetes.sh
Created March 31, 2021 13:12
export-kubernetes.sh
#!/usr/bin/env bash
set -e
CONTEXT="$1"
if [[ -z ${CONTEXT} ]]; then
echo "Usage: $0 KUBE-CONTEXT"
exit 1
fi