Skip to content

Instantly share code, notes, and snippets.

@JamesCullum
JamesCullum / untag-old-gitlab-images.py
Last active March 18, 2024 15:37
Gitlab doesn't have a functionality to automatically untag old images (https://gitlab.com/gitlab-org/gitlab-ce/issues/25322). You can use this script to do that for you using the API from any host with HTTP connection (doesn't require access to the server via SSH). Please be aware that you will need a separate cronjob to purge all untagged images.
#!/usr/bin/env python3
'''
DEVELOPMENT SPONSORED BY
PANASONIC INFORMATION SYSTEMS COMPANY EUROPE
Interested in a job? Apply below:
https://application.job.panasonic.eu/data/ruP0pHQvHrGZJKvL/rc.php?nav=jobsearch&custval12=ite&lang=EN&custval11=PBSEU_GER
'''
@JamesCullum
JamesCullum / main.dart
Created January 27, 2020 22:18
Calculate intermediate point in percentage between two geographic location by latitude / longitude
/*
MIT License
Copyright (c) 2020 JamesCullum (Pseudonym)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@JamesCullum
JamesCullum / import-gitlab-variables.sh
Last active March 19, 2024 07:16
Import all CI/CD variables from Gitlab API and add them to the bash shell for further usage. Made for Ubuntu. Can be combined neatly with Cloud IDEs such as goormIDE to always load the project CI variables into the editor.
#!/bin/bash
# works with /bin/sh as well
# requires sudo permission
apt-get -y install jq
curl --header "PRIVATE-TOKEN: <token>" "https://gitlab.com/api/v4/projects/1/variables" |
jq -c '.[]' |
while IFS=$"\n" read -r c; do
key=$(echo "$c" | jq -r '.key')
val=$(echo "$c" | jq -r '.value')
@JamesCullum
JamesCullum / gitlab-free-rollback-on-issues.sh
Created January 21, 2021 16:27
Bash script to automatically rollback to the last successful pipeline, by re-running the deployment job of it. Should be run with sufficient time after the previous jobs to make sure the check can properly know if the startup failed or not.
#!/bin/bash
if curl --output /dev/null --silent --head --fail "http://127.0.0.1:80"; then
echo "Website appears to be available"
else
echo "Website not available, initiating rollback"
LASTSUCCESSPIPELINE=$(curl -k --silent --header "PRIVATE-TOKEN: $CI_JOB_TOKEN" "https://gitlab.example.com/api/v4/projects/1/pipelines?status=success&scope=finished" | jq '.[0].id')
if [ -z "$LASTSUCCESSPIPELINE" ]; then
echo "Cannot get last pipeline id"
@JamesCullum
JamesCullum / zollsoft.json
Last active May 28, 2021 12:02
Using the Chrome plugin UI.VISION (https://chrome.google.com/webstore/detail/uivision-rpa/gcbalfbdmfieckjlnblleoemohcganoc), check every 3s on a zollsoft.de calendar if a vaccination appointment for Johnson&Johnson or BionTech is available, and if so, take the first appointment and book it
{
"Name": "zollsoft - vaccine book",
"CreationDate": "2021-5-28",
"Commands": [
{
"Command": "store",
"Target": "3",
"Value": "!timeout_wait",
"Description": ""
},
@JamesCullum
JamesCullum / sort_people_into_rooms.go
Created November 14, 2021 11:26
Simple algorithm in Golang to sort people into rooms/groups: https://play.golang.org/p/oLZZ01dyI5o
package main
import (
"fmt"
"math"
"strconv"
"strings"
)
func main() {
@JamesCullum
JamesCullum / mysqli-prepared-helper.php
Created October 16, 2022 15:53
Helper class and method to easily use PHP prepared statements (using PHP 8.1.0+)
<?php
// Helper for prepared statements using main connection in global variable $db
// Class is used, so that we can use __destruct to close connections automatically
class PSQLWrapper {
private $stmt;
private $query_type;
public function __construct($query, $vars = false) {
global $db;
@JamesCullum
JamesCullum / immich-docker-config.md
Last active March 28, 2024 04:30
docker-compose.yml for immich with WAF, DDoS protection, image resizing and without port forwarding

Setup Immich via Docker Compose with WAF, CDN, DDoS protection, no port forwarding and automated image resizing

In this guide, we are using the docker compose setup that is recommended by the Immich team. Once everything is configured and running in your local network, we can expand on it.

The first recommended step is to use Cloudflare Tunnel to make your local instance globally available. This is free and you benefit from the native DDoS protection, WAF and CDN from Cloudflare. The cloudflared daemon basically makes an outgoing connection to Cloudflare and makes the designed interfaces available on the internet, without granting access to undesired parts of the network.

Start off by creating a Cloudflare account, going into the "Zero Trust" portion of the account and add a new tunnel.

@JamesCullum
JamesCullum / auth0-register-login-example.php
Created June 14, 2023 11:44
Automatically log in a user in PHP with a known email address and password. For example if you want to register and sign in a user, you can create the user via management API with a random password and then use it to sign the user in.
<?php
require_once(__DIR__."/vendor/autoload.php"); // Load SDK via Composer
// Initialize SDK like below - read Auth0 documentation for more information
$httpHost = empty($_SERVER["HTTP_X_FORWARDED_HOST"]) ? $_SERVER['SERVER_NAME'] : $_SERVER["HTTP_X_FORWARDED_HOST"];
$auth0 = new \Auth0\SDK\Auth0([
'domain' => $_ENV['AUTH0_DOMAIN'],
'clientId' => $_ENV['AUTH0_CLIENT_ID'],
'clientSecret' => $_ENV['AUTH0_CLIENT_SECRET'],
'cookieSecret' => $_ENV['AUTH0_COOKIE_SECRET'],