Skip to content

Instantly share code, notes, and snippets.

View davidegreenwald's full-sized avatar

David Greenwald davidegreenwald

View GitHub Profile
@davidegreenwald
davidegreenwald / Makefile
Last active July 3, 2023 20:25
Require a version in a Makefile
## Make version management ##
# For Mac users: ensure we aren't using the outdated 2004 3.81 release shipped with Macs
# or a particularly old GNU Make
MAKE_REQUIRED_MAJOR_VERSION := 4
MAKE_VERSION := $(shell $(MAKE) --version | head -1 | cut -d ' ' -f 3)
MAKE_MAJOR_VERSION := $(shell echo $(MAKE_VERSION) | cut -d '.' -f 1)
COMPARE_MAKE_VERSIONS := $(shell printf "$(MAKE_MAJOR_VERSION)\n$(MAKE_REQUIRED_MAJOR_VERSION)" | sort | head -1)
@davidegreenwald
davidegreenwald / settings.json
Created July 2, 2023 03:46
vscode initial set-up settings.json
{
// Don't track or bother me
"telemetry.telemetryLevel": "off",
"extensions.ignoreRecommendations": true,
// Turn off interface features
"editor.minimap.enabled": false,
"workbench.statusBar.visible": false,
"breadcrumbs.enabled": false,
@davidegreenwald
davidegreenwald / .bash_profile
Last active February 16, 2023 18:30
asdf automatic patch updates
# asdf does not have brew-like update functionality and "latest" cannot be used in a .tool-versions file
# making keeping up with new semantic versions a manual and laborious process
# This shell profile function automates this away and will patch update all local .tool-versions packages
# it could be refactored to apply globally or use flags to apply to a selected location
asdf_patch () {
if [ -f ./.tool-versions ]; then
# ensure .tool-versions has a closing newline or bash will skip the last app
@davidegreenwald
davidegreenwald / WordPress MySQL Options Table Query
Created December 21, 2019 00:12
Giant union of queries to get WordPress options table data
# Giant union of queries to get all the information you possibly need about your options table
# change wp_options in all locations to match your WP table's prefix
SELECT COUNT(*) as `Rows`,
'All rows' as `Status`,
ROUND(
SUM(
LENGTH(
CONCAT(option_id, option_name, option_value, autoload)
)
@davidegreenwald
davidegreenwald / delete-webp-with-attachment.php
Last active February 18, 2018 05:38
WordPress function to delete add-on .webp files with their paired attachments
<?php
/*
Plugin Name: Delete webp files with image attachments
*/
/*
Make sure to remove .webp files generated by EWWW or manually when their
parent .jpg image and thumbnails are deleted.
This allows you to wipe the EWWW database table, which bloats quickly. If the db is wiped normally, deleting images will leave orphan .webp files.
@davidegreenwald
davidegreenwald / WordPress-wp_posts-MySQL-data-size
Last active January 4, 2018 11:15
MySQL statement for WordPress wp_posts table breaking down data size for each post_type
-- This will show you the size of post, revision, attachment and other fields in `wp_posts`
-- this method can be applied to any WordPress table to get a breakdown of clutter and data use
-- this will not get you index size, but WP indexes are typically a small fraction of overall table size
SELECT post_type
COUNT(*) AS NUM, -- adds a column with the number of rows for each key value for comparison
SELECT post_type, COUNT(*) AS NUM,
(SUM(LENGTH(ID) -- add all column data together to group the total row data by post_type
+LENGTH(post_author)
+LENGTH(post_date)
+LENGTH(post_date_gmt)
@davidegreenwald
davidegreenwald / modular-typography-variables.scss
Last active December 7, 2017 19:10
2 modular typography scales for different screen sizes with CSS variables and Sass fallbacks
/**
* CSS variables have 77% global browser support
* and don't work in IE at all
* so we can use Sass for a fallback
* @link https://caniuse.com/#search=css%20variables
*/
/**
* Set fallback base font and scale ratio with Sass
* Use these numbers with :root when removing fallback