This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put the thing you need to find here, like this gnarly SQL. | |
# It has a bunch of annoying characters that sed doesn't like, | |
# so we have to escape them. | |
KEYWORD="SET @@GLOBAL.GTID_PURGED=/*!80000 '+'*/ '';"; | |
# Escape the gnarly stuff | |
ESCAPED_KEYWORD=$(printf '%s\n' "$KEYWORD" | sed -e 's/[]\/$*.^[]/\\&/g'); | |
# Now we can find and replace the now-escaped text | |
sed "s/$ESCAPED_KEYWORD/$ESCAPED_REPLACE/g" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pipes data from one MySQL database into another. | |
# Tested with AWS Aurora MySQL (using a 5.7-compatible version of MySQL) to AWS RDS MySQL 8.0. | |
# Probably only suitable for small (<1 TB) databases. | |
# It takes a long time, and if it breaks halfway through you just have to start over from scratch. | |
# Probably not suitable for production without a bunch more work. | |
export $SOURCE_USER= | |
export $SOURCE_HOST= | |
export $SOURCE_PW= | |
# Needs to be a comma-separated list of tables, i.e., user,sale,item |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Favicons | |
======== | |
They're a huge pain in the ass. | |
Use this website: https://realfavicongenerator.net/ | |
For more, read this: https://stackoverflow.com/questions/18301745/how-to-set-up-a-favicon/26768184 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- It's often super useful to generate a timseries-based histogram | |
-- of records counts over a period time, grouped into arbitrary | |
-- timedelta chunks. | |
-- Imagine we have a table like this. | |
-- It has a datetime field, dt, | |
-- some special key somekey (imagine its a foreign key or | |
-- some other useful value that you want to filter by), | |
-- and an index on (somekey, dt) | |
CREATE TABLE `foo` ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import typing | |
from datetime import datetime | |
import boto3 | |
from botocore.exceptions import ClientError | |
def create_or_stream_to_log( | |
aws_cli_logs, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
import MySQLdb | |
import MySQLdb.cursors | |
import logging | |
from django.conf import settings | |
log = logging.getLogger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Example of how to use Percona's online schema changer tool. | |
# Tips! | |
# Don't put any semicolons in your schema commmands! | |
# Separate schema commands by commas; i.e., ADD COLUMN y_id bigint NULL, ADD CONSTRAINT y_fk FOREIGN KEY (y_id) REFERENCES y(y_id)" | |
# When testing, remove the --execute flag! | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import signal | |
from threading import Thread | |
import time | |
class MyThread(Thread): | |
def __init__(self): | |
super().__init__() | |
self._stopped = False | |
def run(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Deletes data in the given table. | |
# This takes the strategy of deleting based on | |
# some indexed key, possibly the primary key. | |
# It will repeatedly delete the first 1000 | |
# records found up to the maximim $MAXVAL. | |
# This seems to have OK performance when working | |
# against a small Aurora instance. | |
# It deletes around 100,000 records every minute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pt-online-schema-change \ | |
--execute \ | |
--progress time,1 \ | |
--print \ | |
--recursion-method=none \ | |
-h my_host \ | |
-u root \ | |
--ask-pass \ |
OlderNewer