Skip to content

Instantly share code, notes, and snippets.

View jirutka's full-sized avatar
🇺🇦
Слава Україні!

Jakub Jirutka jirutka

🇺🇦
Слава Україні!
View GitHub Profile
@jirutka
jirutka / README.md
Last active June 3, 2024 12:16
Simple Keepalived notify script for Valkey/Redis master-replica failover

This is a simple solution for when you use keepalived with VRRP to failover between two instances of an application (e.g. nginx) that uses Redis/Valkey.

It doesn’t provide a high guarantee of data consistency, so it’s only suitable for caches, user sessions and similar!

keepalived.conf example:

vrrp_instance vi {
    ...
    notify "/etc/keepalived/scripts/notify_valkey.sh"
}
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"realm": {
"type": "string"
},
@jirutka
jirutka / qm-replace-disk
Last active May 16, 2023 20:02
Replace disk in the specified VM template in Proxmox with the given image.
#!/bin/sh
# SPDX-FileCopyrightText: 2023 Jakub Jirutka <jakub@jirutka.cz>
# SPDX-License-Identifier: MIT
set -eu
PROGNAME='qm-replace-disk'
VERSION='0.1.0'
# Defaults
DISK='scsi0'
@jirutka
jirutka / iter_chunks_exact.rs
Last active January 5, 2023 16:38
Iterator::array_chunks for stable Rust 1.66
pub(crate) struct ChunksExact<const N: usize, I> {
iter: I,
}
impl<const N: usize, I: Iterator<Item = T>, T> Iterator for ChunksExact<N, I> {
type Item = [T; N];
fn next(&mut self) -> Option<Self::Item> {
assert_ne!(N, 0);
#include <stdbool.h>
typedef char* str;
#define GENERATE_OPTION_TYPES(Option) \
Option(int) \
Option(str)
#define GENERATE_RESULT_TYPES(Result) \
Result(str, int) \
@jirutka
jirutka / radacct-rotate
Created September 21, 2021 21:32
Script for compressing and later removing old FreeRADIUS' radacct log files with "-YYYYMMDD" suffix #freeradius #logrotate
#!/bin/sh
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2021 Jakub Jirutka <jakub@jirutka.cz>
#---help---
# Usage: radacct-rotate [options]
#
# Compress and later remove old FreeRADIUS' radacct log files with "-YYYYMMDD"
# suffix.
#
# Options:
@jirutka
jirutka / arch-linux-installation.md
Last active December 13, 2023 01:09
My notes for installing Arch Linux on encrypted Btrfs with UEFI Secure Boot on ThinkPad T14s

Arch Linux Installation

1. Securely erase drive

cryptsetup open --type plain -d /dev/urandom /dev/nvme0n1 to-be-wiped
dd if=/dev/zero of=/dev/mapper/to-be-wiped bs=1M status=progress
cryptsetup close to-be-wiped
wipefs -a /dev/nvme0n1
@jirutka
jirutka / zeme.json
Created May 8, 2021 21:44
Číselník zemí z onlinescitani.cz
{
"poradiCse": [
"004",
"248",
"008",
"012",
"016",
"850",
"020",
"024",
@jirutka
jirutka / array_uniq.sql
Created April 2, 2021 21:14
Example of PostgreSQL trigger function to sort and deduplicate an array
create function array_uniq (a anyarray) returns anyarray
immutable
language sql
as $$
select array_agg(distinct x) from unnest(a) x;
$$;
comment on function array_uniq is
'Sorts and deduplicates elements of an array.';
create function trg_person_roles_normalize () returns trigger
@jirutka
jirutka / trg_check_array_elements_column_uniq.sql
Created April 2, 2021 21:11
PostgreSQL constraint trigger to check if each array element is unique within the table
-------------------------------------------------------------------------------
-- EXAMPLE USAGE
--
-- create table specialization (
-- id bigserial,
-- name text not null,
-- study_plan_codes text[] not null default '{}'
-- )
--
-- create constraint trigger study_plan_codes_unique_check