Skip to content

Instantly share code, notes, and snippets.

View heathdutton's full-sized avatar
🕴️
Headlines are unsanitized input. Attention is prod.

Heath Dutton🕴️ heathdutton

🕴️
Headlines are unsanitized input. Attention is prod.
View GitHub Profile
@heathdutton
heathdutton / assasin.sql
Last active June 29, 2023 17:31
Assassinates matching queries.
DELIMITER ;;
DROP PROCEDURE IF EXISTS `assasinate`;;
CREATE PROCEDURE `assasinate`(queryportion VARCHAR(255))
BEGIN
DECLARE sql_string MEDIUMTEXT;
DECLARE count MEDIUMINT;
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SET FOREIGN_KEY_CHECKS = 0;
SET @count = 0;
SET @sql_string := 'tmp';
@heathdutton
heathdutton / this-is-fine.gif
Created February 3, 2022 19:35 — forked from mihaicodes/this-is-fine.gif
This is fine gif.
this-is-fine.gif
@heathdutton
heathdutton / This is fine.md
Created February 3, 2022 19:35 — forked from 25A0/This is fine.md
This is fine. ASCII art

This is fine. ASCII art

preview

There are two versions, one is for dark letters on a bright background, the other one for bright letters on a dark background.

The bright on dark version looks better, so go for that one if you can :)

Dark letters on a bright background

@heathdutton
heathdutton / recover_commit_latency.sql
Last active December 6, 2021 19:18
MySQL - Automatically recover from a big commit latency bottleneck
-- Note, this will CANCEL commits if they take more than 20s to complete.
-- It is assumed that if you have commit latency greater than 20s that something is terribly wrong,
-- and you are now losing data due to a lack of throughput already.
-- This will help resume opperation at the cost of potentially dropping locking changes.
-- Create a stored proceedure that can recover from a commit latency lock-up
-- Do not run multiple of this at once.
-- When running loop and kill till there are none to kill.
DROP PROCEDURE IF EXISTS `recover_commit_latency`;
DELIMITER ;;
@heathdutton
heathdutton / TimeZoneOptionCollection.php
Created January 28, 2020 20:52
Dynamic collection of supported PHP Timezones. Grouped by country, with dynamic abbreviations, DST indicators, and future-proofing. For making useful and clean select2 (or similar) dropdown selectors. Better than all the hard-coded solutions I could find.
<?php
/**
* Class TimeZoneOptionCollection
*
* Dynamic collection of supported PHP Timezones:
* - Grouped by country
* - Commonly used abbreviations
* - DST indicators
* - Future-proof (leans on PHP for timezones).
{{ $var }} - Echo content
{{ $var or 'default' }} - Echo content with a default value
{{{ $var }}} - Echo escaped content
{{-- Comment --}} - A Blade comment
@extends('layout') - Extends a template with a layout
@if(condition) - Starts an if block
@else - Starts an else block
@elseif(condition) - Start a elseif block
@endif - Ends a if block
@heathdutton
heathdutton / cloudways-mautic.sh
Last active February 20, 2020 19:02
Recommended cron tasks for Mautic 2 in Cloudways.
# Recommended cron tasks for Mautic 2 in Cloudways.
# All tasks are ran as www-data
# Output is ignored to avoid log file overhead.
# --quiet is used to reduce MySQL overhead on some tasks.
# --max-contacts is used to prevent one object's backlog from locking updates for other object.
# SEGMENTS
# Update all segments.
*/5 * * * * www-data php applications/mautic/public_html/app/console mautic:segments:update --max-contacts=10000 --quiet >/dev/null 2>&1
@heathdutton
heathdutton / campaigns-worth-unpublishing.sql
Last active August 15, 2023 16:13
Find Mautic campaigns that can be unpublished to speed up campaign processing.
-- Find dead campaigns, first discern *active* campaigns.
SET GROUP_CONCAT_MAX_LEN = 999999999;
-- What is the oldest Lead ID we should care about ( 90 days )
SELECT id FROM leads WHERE date_added = DATE_SUB(NOW(), INTERVAL 90 DAY) LIMIT 1 INTO @lead_id;
-- Get list of all campaigns that were modified in last yr.
SELECT GROUP_CONCAT(c.id) FROM `campaigns` c WHERE c.is_published = 1 OR c.date_modified > DATE_SUB(NOW(), INTERVAL 365 DAY) INTO @active_campaigns;
-- SELECT @lead_id, @active_campaigns;
@heathdutton
heathdutton / auto_increment_explosion_warning_system.sql
Created August 5, 2019 17:39
Find tables that are the closets to approaching their max auto-increment value in MySQL (and need to be made unsigned or BIGINT).
SELECT
TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME,
DATA_TYPE,
COLUMN_TYPE,
IF(
LOCATE('unsigned', COLUMN_TYPE) > 0,
1,
0
@heathdutton
heathdutton / panic-at-the-disco.sql
Last active July 30, 2019 21:47
Mautic campaign_lead_event_log_new hit 2147483647 rows.
-- So this table hit the max-int value for the auto_increment column id.
-- Really, such columns should be unsigned so they can go up to 4 bil.
ALTER TABLE campaign_lead_event_failed_log DROP FOREIGN KEY `FK_E50614D2EA675D86`;
-- This took ~3 minutes.
ALTER TABLE campaign_lead_event_failed_log CHANGE log_id log_id INT(11) UNSIGNED NOT NULL;
-- The next table was too large to modify in place, was causing an outage, so we had to do a swap like so:
CREATE TABLE campaign_lead_event_log_new LIKE campaign_lead_event_log;
ALTER TABLE campaign_lead_event_log_new CHANGE id id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT;