Skip to content

Instantly share code, notes, and snippets.

View silashansen's full-sized avatar

Silas Hansen silashansen

View GitHub Profile
@silashansen
silashansen / .env
Created November 14, 2024 13:38
Vault login
VAULT_TOKEN=<your token>
@silashansen
silashansen / replace_in_repos.py
Created October 17, 2024 11:07
Find and replace a string within a protected repository using automatic Merge Request create/merge
import os
import shutil
import gitlab
from git import Repo
import time
# Configuration
GITLAB_URL = "https://git.acme.dk"
GITLAB_TOKEN = "..."
@silashansen
silashansen / delete_image.sh
Created August 8, 2024 13:51
Delete image from repository
This is confirmed working with Harbor v2.0.0
# Parameters ------------------------
HARBOR_URL="https://reg.registry.dk"
HARBOR_USER="username"
HARBOR_PASSWORD="secret"
PROJECT="project"
REPOSITORY="repository"
TAG="0.0.1"
@silashansen
silashansen / kasten-access.yaml
Created June 26, 2024 11:35
Give access to a user in K10
# Step 1: Use the kasten UI to create a role (<role>)
# Create service account for those who needs access
kubectl create serviceaccount <user> --namespace kasten-io
# For the namespace that the user needs access to:
kubectl create rolebinding backup_manager1 --namespace <namespace> \
--clusterrole=<role> \
--serviceaccount=kasten-io:<user>
# THIS IS A VERY HACKY AD-HOC SOLUTION TO BALANCE NODES BASED ON MEMORY USAGE ACROSS THE CLUSTER
import subprocess
import json
import time
def execute_kubectl_command(command):
"""Executes a kubectl command and returns the output."""
full_command = ["kubectl"] + command.split()
result = subprocess.run(full_command, capture_output=True, text=True)
@silashansen
silashansen / fix_rgb.sh
Last active January 5, 2024 10:19
Force RGB on MacOS
#!/bin/bash
fix_rgb() {
fixes=0
dryrun=false
if [ ! -t 0 ]; then
read -p "Do you want to proceed with fixing? (y/n): " answer
if [ "$answer" = "n" ]; then
dryrun=true
@silashansen
silashansen / create_gcp_lb.md
Last active October 9, 2023 20:53
Create Google Loadbalancer from CLI

Global Load Balancer to Managed Instance Group

Create the Global Load Balancer

Setup some variables first

export PROJECT_ID=$(gcloud config get-value project)
export REGION=europe-west3 # should be the same as your mig
export MIG_NAME=service-x-mig # or whatever you already have
@silashansen
silashansen / elevator.js
Created August 25, 2023 23:57
Elevator Saga
{
init: function(elevators, floors) {
// helper function to check if a floor is already queued
function isFloorQueued(elevator, floorNum) {
return elevator.destinationQueue.indexOf(floorNum) > -1;
}
function isFloorQueuedForAnyElevator(floorNum) {
for (let e = 0; e < elevators.length; e++) {
@silashansen
silashansen / device_tracker_agg.sql
Created August 25, 2023 23:50
Home Assistant Device tracker state duration aggregation for SQLite
WITH p AS (
WITH q AS (
WITH y AS (
WITH x as (
SELECT
sm.entity_id,
s.state,
s.last_updated_ts,
COALESCE(LAG(s.state) OVER (partition by sm.entity_id ORDER BY last_updated_ts ASC), s.state) as last_state
FROM states s
@silashansen
silashansen / api_tests.py
Created August 18, 2023 08:13
Webshop tests
# BEGIN: 8f7d6h3j4k5l
import unittest
import requests
import jwt
import time
class TestAPI(unittest.TestCase):
token = None
api_basepath = "https://api-test.xl-byg.dk"