Skip to content

Instantly share code, notes, and snippets.

View Blackskyliner's full-sized avatar

Christoph Landsdorf Blackskyliner

View GitHub Profile
@kjmph
kjmph / A_UUID_v7_for_Postgres.sql
Last active April 23, 2024 15:26
Postgres PL/pgSQL function for UUID v7 and a bonus custom UUID v8 to support microsecond precision as well. Read more here: https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
create or replace function uuid_generate_v7()
returns uuid
as $$
begin
-- use random v4 uuid as starting point (which has the same variant we need)
-- then overlay timestamp
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string
return encode(
@kenji4569
kenji4569 / ulid_converter.sql
Last active March 23, 2024 13:48
ULID (26 characters in Crockford's base32) conversion for MySQL function
# Define ULID_DECODE and ULID_ENCODE which convert a ulid string to a binary and vice versa.
delimiter //
DROP FUNCTION IF EXISTS ULID_DECODE//
CREATE FUNCTION ULID_DECODE (s CHAR(26)) RETURNS BINARY(16) DETERMINISTIC
BEGIN
DECLARE s_base32 CHAR(26);
SET s_base32 = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(UPPER(s), 'J', 'I'), 'K', 'J'), 'M', 'K'), 'N', 'L'), 'P', 'M'), 'Q', 'N'), 'R', 'O'), 'S', 'P'), 'T', 'Q'), 'V', 'R'), 'W', 'S'), 'X', 'T'), 'Y', 'U'), 'Z', 'V');
RETURN UNHEX(CONCAT(LPAD(CONV(SUBSTRING(s_base32, 1, 2), 32, 16), 2, '0'), LPAD(CONV(SUBSTRING(s_base32, 3, 12), 32, 16), 15, '0'), LPAD(CONV(SUBSTRING(s_base32, 15, 12), 32, 16), 15, '0')));
END//

I have been an aggressive Kubernetes evangelist over the last few years. It has been the hammer with which I have approached almost all my deployments, and the one tool I have mentioned (shoved down clients throats) in almost all my foremost communications with clients, and it was my go to choice when I was mocking my first startup (saharacluster.com).

A few weeks ago Docker 1.13 was released and I was tasked with replicating a client's Kubernetes deployment on Swarm, more specifically testing running compose on Swarm.

And it was a dream!

All our apps were already dockerised and all I had to do was make a few modificatons to an existing compose file that I had used for testing before prior said deployment on Kubernetes.

And, with the ease with which I was able to expose our endpoints, manage volumes, handle networking, deploy and tear down the setup. I in all honesty see no reason to not use Swarm. No mission-critical feature, or incredibly convenient really nice to have feature in Kubernetes that I'm go

@heppu
heppu / ARCH_INSTALL.MD
Last active February 27, 2022 17:01
Installing Arch with GPT, dm-crypt, LUKS, LVM and systemd-boot

Create bootable USB

dd bs=4M if=/path/to/archlinux.iso of=/dev/sdx status=progress oflag=sync

Boot from USB and set prepare system

loadkeys <your-keymap>
@tjamps
tjamps / README.md
Last active February 29, 2024 14:57
Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authentication
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 2 framework. The following SF2 bundles are used :

@stbuehler
stbuehler / bma2otp.rb
Created January 25, 2014 14:10
Decode the Battle.net Mobile Authenticator (android) secret data into an otpauth url. Requires a way to access the private data of the application (i.e. a rooted android).
#!/usr/bin/ruby
# REQUIRES:
# * rooted android, as otherwise you can't read the applications private data
# * to display the qr code "qrencode" (http://fukuchi.org/works/qrencode/)
# and "display" from ImageMagick
# This script "decrypts" the token from the internal state of the
# Battle.net Mobile Authenticator on android application, converting
# it into an "otpauth" url (https://code.google.com/p/google-authenticator/wiki/KeyUriFormat)
@snipe
snipe / gist:4256150
Created December 11, 2012 05:38
Apache Ant build.xml file for PHPUnit+Jenkins+Ant+Symfony2
<?xml version="1.0" encoding="UTF-8"?>
<!-- Set some basic project information and targets -->
<project name="My Symfony2 Project" default="build">
<target name="build"
depends="prepare, vendors, dbupdate, fixtures, lint, phploc, phpmd, phpcpd, phpcs, phpunit"/>
<target name="build-parallel"
depends="prepare, vendors, dbupdate, fixtures, lint, tools-parallel, phpcpd, phpunit"/>
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite