Skip to content

Instantly share code, notes, and snippets.

View sqlbot's full-sized avatar

Michael Ezzell sqlbot

View GitHub Profile
@sqlbot
sqlbot / error.xsl
Last active October 9, 2024 15:18
Rewrite XML error responses from S3 REST endpoints using HAProxy 1.6 and Lua
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<!-- This stylesheet will be loaded by the browser, when the Lua script, below -->
<!-- inserts a reference to it in the XML error response from S3. -->
<!-- Place this file in the bucket as /error.xsl -->
<!-- set the Content-Type to text/xsl and make the file public -->
<!-- also you should probably remove this comment block :) -->
<html>
<title>We&#8217;ve encountered a problem</title>
@sqlbot
sqlbot / mysql-err.lua
Last active January 8, 2022 17:20
Custom failure message to MySQL clients when no backends are available with HAProxy 1.6 with Lua
-- With the addition of Lua to HAProxy 1.6, we can generate a custom error message
-- to any client requesting a connection, identifying the proxy that returned the error
-- by its ec2 instance ID (or any other meaningful identifier in your environment),
-- providing a cleaner method of reporting failure to the caller than just opening and closing the connection,
-- which would be the default behavior with no backend servers healthy, and could lead to
-- troubleshooting the wrong thing.
-- the response packet we craft is a valid packet in the MySQL client/server protocol,
-- so any client should understand and be able to report the error back up the stack; viz.:
@sqlbot
sqlbot / nest_rebuild.sql
Created September 27, 2012 13:34
Outer Stored Procedure for Building Nested Set From Scratch
DELIMITER $$
DROP PROCEDURE IF EXISTS `nest_generic_rebuild` $$
CREATE PROCEDURE `nest_generic_rebuild` ()
MODIFIES SQL DATA
BEGIN
DECLARE counter INT DEFAULT 0;
DECLARE nest_depth INT DEFAULT 1;
DECLARE my_left_id INT;
DECLARE my_nest_depth INT;