Skip to content

Instantly share code, notes, and snippets.

@lovromazgon
lovromazgon / tail_test.go
Last active April 15, 2022 15:03
Test for bug in nxadm/tail, see https://github.com/nxadm/tail/issues/41
package main
import (
"context"
"fmt"
"os"
"sync"
"testing"
"time"
@lovromazgon
lovromazgon / sem-copy-secret.sh
Created January 15, 2021 17:00
Duplicate a SemaphoreCI secret.
#!/bin/bash
# Usage:
# ./sem-copy-secret.sh [source secret name] [target secret name]
set -e
SOURCE_SECRET="$1"
TARGET_SECRET="$2"
echo "Copying secret $SOURCE_SECRET to $TARGET_SECRET"
@lovromazgon
lovromazgon / mute_twist.sh
Last active March 13, 2024 11:02
Mute Twist thread
#!/bin/bash
# Mutes a Twist thread for some time (30 minutes by default).
#
# Usage:
# ./mute_twist.sh <email> <password> <thread ID> [<minutes>]
EMAIL=$1
PASSWORD=$2
THREAD_ID=$3
MINUTES=${4:-30}
@lovromazgon
lovromazgon / README.md
Last active October 19, 2023 21:44
Schedule starting/stopping a CloudSQL instance on GCP

To use this cloud function follow these steps:

  1. Create a pub/sub topic which will be used to trigger the cloud function.
  2. Create the cloud function and copy in the code below.
    1. Make sure to set the correct project ID in line 8.
    2. Set the trigger to Pub/Sub and choose the topic created in step 1.
  3. Create a cloud scheduler job to trigger the cloud function on a regular basis.
    1. Choose the frequency when you want the cloud function to be triggered.
    2. Set the target to Pub/Sub and define the topic created in step 1.
    3. The payload should be set to start [CloudSQL instance name] or stop [CloudSQL instance name] to start or stop the specified instance (e.g. start my_cloudsql_instance will start the CloudSQL instance with the name my_cloudsql_instance)
@lovromazgon
lovromazgon / connect_box_restart.sh
Created June 25, 2019 08:30
This script restarts the ConnectBox from Magenta, an ISP in Austria.
#!/usr/bin/env bash
#
# This script restarts the ConnectBox from Magenta, an ISP in Austria.
#
# Run this script with LOGIN_USER and LOGIN_PASS env variables set to the
# username and password of the router and it will restart it.
#
# LOGIN_USER is 'NULL' by default, that is also the default router setting.
#
# Example usage:
@lovromazgon
lovromazgon / fix-grub.sh
Last active March 13, 2024 09:58
This script fixes GRUB for systems, that were installed according to the Manual Full System Encryption guide (https://help.ubuntu.com/community/ManualFullSystemEncryption). It is inspired by the original script used in the guide and reuses a lot of parts from it. Use an Ubuntu Live CD / USB to get to a terminal and run the script from there.
#!/usr/bin/env bash
####################################################################################################
#
# FIX GRUB FOR ENCRYPTED INSTALLATION
#
# This script is based on the Troubleshooting part of the Manual Full System Encryption for Ubuntu.
# See https://help.ubuntu.com/community/ManualFullSystemEncryption/Troubleshooting
#
# This is NOT AN OFFICIAL Ubuntu script, it can and will break your system. Use at own risk.
@lovromazgon
lovromazgon / github_projects_wip.user.js
Last active February 21, 2019 09:15
Tampermonkey script which changes the background of a column in Github projects if the work in progress limit is exceeded.
// ==UserScript==
// @name Github Projects work in progress limit
// @namespace https://github.com/lovromazgon
// @version 0.4
// @updateURL https://gist.github.com/lovromazgon/1e02018cafa132d0655e8c6850f18e17/raw/github_projects_wip.user.js
// @downloadURL https://gist.github.com/lovromazgon/1e02018cafa132d0655e8c6850f18e17/raw/github_projects_wip.user.js
// @description Changes the background of a column in Github projects if the work in progress limit is exceeded.
// @author Lovro Mažgon
// @match https://github.com/toggl/*/projects/*
// @grant none
@lovromazgon
lovromazgon / toggle-go-version.sh
Created June 13, 2018 07:35
Simple script to toggle between Go versions.
#!/bin/bash
echo "Available go versions:"
result=$(ls -1 /usr/local/ | grep -i "go" | grep -v "^go$")
echo "$result" | nl
echo ""
printf "Which version shall it be: "
read -r num
@lovromazgon
lovromazgon / switch_audio_sink.sh
Last active March 13, 2024 11:02
Script for switching between 2 audio sinks
#!/bin/bash
set -euo pipefail # strict mode
currentSink() { pacmd list-sinks | awk '{if($1=="*"){print $3;}}'; }
inactiveSink() { pacmd list-sinks | awk '{if($1=="index:"){print $2;}}'; }
sinkInputs() { pacmd list-sink-inputs | awk '{if($1=="index:")print $2}'; }
current_sink="$(eval currentSink)"
inactive_sink="$(eval inactiveSink)"
sink_inputs="$(eval sinkInputs)"
@lovromazgon
lovromazgon / .bashrc
Created January 19, 2018 12:33
Support for multiple GOPATHs - set GOPATH on change of directory
# with these functions you can have multiple gopath directories residing in /opt, where each gopath folder starts with "go-"
# when cd-ing to one of these directories (or any directory in them, on any level) the GOPATH gets changed automagically
function cd {
# call builtin cd. change to the new directory
builtin cd $@
# call a hook function that can use the new working directory
# to decide what to do
set_gopath
}