Skip to content

Instantly share code, notes, and snippets.

View eastside's full-sized avatar

Adam eastside

View GitHub Profile
@eastside
eastside / sassSvgInliner.js
Last active May 8, 2023 22:55
Svg inliner that works with the latest version of blueprint, sass, webpack, node, etc
// This is a workaround for an outstanding issue in Blueprint as of 5/8/23.
// Issue is here: https://github.com/palantir/blueprint/issues/6051
//
// Basically, there's an issue where Sass-loader in webpack can't use Sass' new API for creating custom functions in Sass.
// Blueprint.js needs to register a custom function to render some svg icons.
// However, I guess the build process in Blueprint doesn't actually use webpack at all (lucky them), so we get to modify Blueprint's nice svg loader code to work with the old API.
// In our webpack.config.mjs file, we import legacySassSvgInlinerFactory and use it instead of sassSvgInlinerFactory.
//
// Taken from https://github.com/palantir/blueprint/blob/develop/packages/node-build-scripts/src/svg/svgOptimizer.mjs
@eastside
eastside / gist:2c96878f91d6f4288112a09f4bfef745
Last active February 3, 2023 05:28
MySQL Online Schema Change Example using Percona
#!/bin/bash
pt-online-schema-change \
--execute \
--progress time,1 \
--print \
--recursion-method=none \
-h my_host \
-u root \
--ask-pass \
@eastside
eastside / run_pt_archive.sh
Created November 22, 2022 19:03
Bulk delete data from Aurora/MySQL
#!/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.
@eastside
eastside / wtf.py
Last active April 20, 2022 04:05
Why does does commenting out line 44 fix this code?
import signal
from threading import Thread
import time
class MyThread(Thread):
def __init__(self):
super().__init__()
self._stopped = False
def run(self):
@eastside
eastside / gist:43c21470ec473089d9dc0ed6aa665a91
Created December 11, 2021 01:32
MySQL_Zero_Downtime_SchemaChange.sh
#!/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!
@eastside
eastside / django_mysql_sscursor.py
Created October 26, 2021 17:59
Django server-side MySQL cursor
from contextlib import contextmanager
import MySQLdb
import MySQLdb.cursors
import logging
from django.conf import settings
log = logging.getLogger(__name__)
@eastside
eastside / aws_logs.py
Created October 25, 2021 00:21
Create or Stream to an AWS CloudFormation Log Group/Stream
import json
import typing
from datetime import datetime
import boto3
from botocore.exceptions import ClientError
def create_or_stream_to_log(
aws_cli_logs,
@eastside
eastside / count_by_timechunk.sql
Last active October 13, 2021 21:40
MySQL count records by a group of time chunks
-- 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` (
@eastside
eastside / favicon_notes.readme
Created October 13, 2021 17:49
favicon generator
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
@eastside
eastside / mysql-migrate.sh
Created October 12, 2021 17:59
Copy a MySQL database using native MySQL tools without a dumpfile
# 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