Skip to content

Instantly share code, notes, and snippets.

@tkhn
tkhn / RenewExpiredGPGkey.md
Created February 16, 2024 19:19 — forked from TheSherlockHomie/RenewExpiredGPGkey.md
Updating expired GPG keys and backing them up 🔑🔐💻

Updating expired GPG keys and their backup 🔑🔐💻

I use a GPG key to sign my git commits.

An error like this one might be a sign of an expired GPG key.

error: gpg failed to sign the data fatal: failed to write commit object
@tkhn
tkhn / terraform_the_missing_manual.md
Created July 1, 2023 17:38 — forked from xirkus/terraform_the_missing_manual.md
Terraform - The Missing Manual

Terrafrom Logo

Terraform - The Missing Manual

Infrastructure-as-Code is a principal that drives modern DevOps practice. I discuss the current state of Terraform and provide some basic guidelines/principles regarding how to structure it's usage for your project.

Tables of Contents

@tkhn
tkhn / php-pools.md
Created March 23, 2023 19:00 — forked from holmberd/php-pools.md
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
@tkhn
tkhn / tcptee.py
Created January 5, 2023 13:46 — forked from shearichard/tcptee.py
tcptee.py is a tee for TCP. It acts as a simple TCP proxy and dumps all traffic onto stdout.
# A tee for TCP, similar to `socal -v`.
#
# | server
# client ---|
# | stdout
import socket
from select import select
import sys
import logging
@tkhn
tkhn / lockpidfile.py
Created January 19, 2022 15:20 — forked from CMCDragonkai/lockpidfile.py
Singleton Process with PID Lock File #python
import os
import fcntl
import contextlib
import time
@contextlib.contextmanager
def lockpidfile(filepath):
with os.fdopen(
os.open(filepath, os.O_RDWR | os.O_CREAT, mode=0o666),
@tkhn
tkhn / advisory_locks_example.sql
Created January 18, 2022 21:32 — forked from toke/advisory_locks_example.sql
Example for advisory locks in postgresql
do $$
DECLARE
ADV_LOCK BOOLEAN DEFAULT FALSE;
LOCK_ID INTEGER DEFAULT 50;
BEGIN
-- EARLY LOCK
-- LOCK_ID := 'tablename'::regclass::integer;
SELECT pg_try_advisory_lock(LOCK_ID) into ADV_LOCK;
RAISE NOTICE 'LOCK_ID: %', LOCK_ID;
IF ADV_LOCK THEN
@tkhn
tkhn / console.php
Created December 8, 2021 22:04 — forked from ziadoz/console.php
Symfony Console Component Example
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Finder\Finder;
@tkhn
tkhn / dump.sql
Created October 26, 2021 12:15 — forked from AlexeyKupershtokh/dump.sql
Postgres DDL to Clickhouse converter
select
concat(
'create table ',
table_name,
'(',
string_agg(
concat(
column_name,
' ',
CASE when is_nullable = 'YES' THEN 'Nullable(' END,
@tkhn
tkhn / pyparted-test.py
Created February 27, 2021 20:18 — forked from kergoth/pyparted-test.py
Example use of pyparted to achieve partition alignments with non-devices that the parted command cannot.
#!/usr/bin/env python
import parted
def add_partition(disk, free, align=None, length=None, fs_type=None, type=parted.PARTITION_NORMAL):
start = free.start
if length:
end = start + length - 1
else:
end = free.end
@tkhn
tkhn / pglogical
Created January 17, 2021 17:56 — forked from ratnakri/pglogical
short tutorial to setup replication using pglogical
Edit /var/lib/postgres/data/postgresql.conf:
# change IP on subscriber
listen_addresses = '*'
wal_level = logical
shared_preload_libraries = 'pglogical'
max_worker_processes = 16
max_wal_senders = 16
max_replication_slots = 16
track_commit_timestamp = on