Skip to content

Instantly share code, notes, and snippets.

@klaussilveira
klaussilveira / gist:554ca0feb7ac42663ac386f738fe8154
Created August 2, 2024 14:42
PostgreSQL: Find Lagged Replication
SELECT slot_name,
pg_wal_lsn_diff(
pg_current_wal_lsn(),
restart_lsn
) AS bytes_behind,
active,
wal_status
FROM pg_replication_slots
WHERE wal_status <> 'lost'
ORDER BY restart_lsn;
@klaussilveira
klaussilveira / gnupg_scdaemon.md
Created July 31, 2024 00:23 — forked from artizirk/gnupg_scdaemon.md
OpenPGP SSH access with Yubikey and GnuPG

NB: This document describles a 'Old-School' way of using Yubikey with SSH

Modern OpenSSH has native support for FIDO Authentication. Its much simpler and should also be more stable with less moving parts. OpenSSH also now has support for signing arbitary files witch can be used as replacement of gnupg. Git also supports signing commits/tags with ssh keys.

Pros of FIDO

  • Simpler stack / less moving parts
  • Works directly with ssh, ssh-add and ssh-keygen on most computers
  • Simpler
  • Private key can never leave the FIDO device

Cons of FIDO

@klaussilveira
klaussilveira / ExmpleSource.cpp
Created August 21, 2023 13:42 — forked from oldmanauz/ExmpleSource.cpp
Simple Flecs TD
/**
Copyright <2021> <Lexxicon Studios LLC.>
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 furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
alter table books
add constraint books_doc_isbn_ok
check(
doc->>'ISBN' is not null and
jsonb_typeof(doc->'ISBN') = 'number' and
(doc->>'ISBN')::bigint > 0 and
length(doc->>'ISBN') = 13
);
@klaussilveira
klaussilveira / hurricane.py
Created June 26, 2020 13:48
Check for hurricanes
import xml.etree.ElementTree as ET
import urllib.request
import re
namespaces = {'nhc': 'http://www.nhc.noaa.gov'}
# Drill: https://www.nhc.noaa.gov/rss_examples/index-at-20130605.xml
xml = urllib.request.urlopen('https://www.nhc.noaa.gov/index-at.xml').read()
root = ET.fromstring(xml)
hurricane = root[0].find('item/nhc:Cyclone', namespaces)
<?php
require '../vendor/autoload.php';
$request = Symfony\Component\HttpFoundation\Request::createFromGlobals();
$context = (new Symfony\Component\Routing\RequestContext())->fromRequest($request);
$configLocator = new Symfony\Component\Config\FileLocator(__DIR__ . '/../config');
$file = '../var/cache/container.php';
if (\file_exists($file)) {
@klaussilveira
klaussilveira / SDL.h
Last active September 19, 2019 20:02
PHP 7.4 FFI + SDL2
#define FFI_SCOPE "SDL"
#define FFI_LIB "libSDL2.so"
typedef uint8_t Uint8;
typedef uint16_t Uint16;
typedef uint32_t Uint32;
typedef uint64_t Uint64;
extern int SDL_Init(Uint32 flags);
extern int SDL_InitSubSystem(Uint32 flags);
if ( $var == 'crazy' && $foo != 'bar' )
seems very unreadable for me.
@klaussilveira
klaussilveira / gist:1391786
Created November 24, 2011 16:50
Github Suggestion Box
Github Suggestion Box
---------------------
Please, put your suggestions here. Octocat thanks you!
* Discussion module for each repository, allowing contributors and users to discuss various aspects of the repository
@klaussilveira
klaussilveira / gist:1189595
Created September 2, 2011 19:24
Branch verification inside Jenkins
#!/bin/bash
if [ "${GIT_BRANCH}" == "origin/master" ]
then
do stuff
else
do other stuff
fi