Skip to content

Instantly share code, notes, and snippets.

View wordpress-dev-phpcs.md

How to run phpcs on WordPress-Develop files without installing PHP

I've been running all my dev projects via Docker to avoid the pitfalls of installing server software on my computer. This also lets me jump between macheines very easily since everything I need is wrapped up in dockerfiles, docker-compose files or package.json scripts.

WordPress development doesn't work like that. The default development environment expects PHP to be installed and will try to run PHPCS validation checks from a local instance of PHP.

Use Composer's Docker image

The official Composer Docker image is extremely versatile. It can run arbitrary shell commands if the passed argument isn't a Composer keyword.

@joemaller
joemaller / wordpress-blocks-min-scripts.md
Last active September 29, 2023 02:41
How WordPress includes minimized script snippets for blocks in use.
View wordpress-blocks-min-scripts.md

WordPress v6.3.1 inlines styles for used blocks via the wp_head hook. However there is an additional wrinkle. If the SCRIPT_DEBUG constant is set and truthy, then a minimized copy of the styles will be inlined. The minimized copy is pre-generated and included with WordPress.

Code for choosing to use the min variant is in wp-includes/blocks.php:

// Check whether styles should have a ".min" suffix or not.
$suffix = SCRIPT_DEBUG ? '' : '.min';
if ( $is_core_block ) {
    $style_path = ( 'editorStyle' === $field_name ) ? "editor{$suffix}.css" : "style{$suffix}.css";
}
@joemaller
joemaller / wsl-port-proxy.json
Created March 3, 2023 20:08
script and config file for configuring WSL 2 portproxy rules
View wsl-port-proxy.json
{
"ports": [3000, 5173, 8000]
}
@joemaller
joemaller / conversion.js
Created November 15, 2022 15:48
Question about preferred code conversion
View conversion.js
// Starting with an API returned data structure like this:
const Parameters = [
{
Name: "PASS",
Type: "SecureString",
Value: "cGFzc3dvcmQ=",
Version: 3,
LastModifiedDate: "2022-11-14T15:13:08.263Z",
ARN: "arn:aws:ssm:us-east-1:678000000000:parameter/PASS",
@joemaller
joemaller / curl-format.txt
Created November 8, 2022 20:13
Template for reporting connection times from curl connections. More here: https://blog.josephscott.org/2011/10/14/timing-details-with-curl/
View curl-format.txt
\n
time_namelookup: %{time_namelookup}\n
time_connect: %{time_connect}\n
time_appconnect: %{time_appconnect}\n
time_pretransfer: %{time_pretransfer}\n
time_redirect: %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
———\n
time_total: %{time_total}\n
@joemaller
joemaller / harrassment-training-bot.js
Created October 6, 2022 14:56
bot for helping test online training. Kind of garbage, but maybe useful in the future.
View harrassment-training-bot.js
/**
* For ADP's 2022 sexual harrassment training
*/
cr = () => {
const next = $('button.next-button:not(.disabled)')
if (next.length) {
next.click();
}
@joemaller
joemaller / case-conversion.md
Created September 23, 2022 20:30
Case Conversion examples
View case-conversion.md

Input: my name is bond

Name Sample
🐪 Camel case myNameIsBond
👨‍🏫 Pascal case MyNameIsBond
🐍 Snake case my_name_is_bond
👩‍🏫 Ada case My_Name_Is_Bond
Ⓜ️ Macro case MY_NAME_IS_BOND
🥙 Kebab case my-name-is-bond
@joemaller
joemaller / index.html
Last active September 9, 2022 16:28 — forked from d3noob/index.html
Add multiple markers in leaflet.js
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Simple Leaflet Map</title>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
</head>
@joemaller
joemaller / setup.sh
Last active October 21, 2023 16:40
Helper script for installing apps on a new Mac
View setup.sh
#!/usr/bin/env bash
# Download this file then run:
# % chmod a+x setup.sh
# % ./setup.sh
# Or run directly from this Gist:
# % curl https://gist.githubusercontent.com/joemaller/55aca1bcffe44558cf93527153d6896a/raw/setup.sh | bash
# Install Homebrew first https://brew.sh
set -u
@joemaller
joemaller / attributes.md
Last active February 6, 2022 17:15
Out of deference to Prettier, I'm switching to filling empty attributes
View attributes.md

Previously, for "cleaner HTML" I tended to prefer something like this:

<?php 
$classes = ['cat', 'dog'];
$classAtt = empty($classes) ? "" : " class='" . implode($classes, ' ') . '"'; 
?>
<div<$= $classAtt ?>>Text</div>

That string concatenation is just gross, but the HTML is "nicer"; the opening tag will either be or.