Skip to content

Instantly share code, notes, and snippets.

@joemaller
joemaller / publish-calendar.ps1
Last active June 25, 2025 19:46
Commands for publishing an Exchange calendar from a sharedMailbox
# Connect and start an Exchange Online PowerShell session
Connect-ExchangeOnline -UserPrincipalName [email protected]
# Publish the calendar
Set-MailboxCalendarFolder -Identity "[email protected]:\Calendar" -PublishEnabled $true -DetailLevel FullDetails -PublishDateRangeFrom ThreeMonths -PublishDateRangeTo OneYear
# Print the Published ICS url
Get-MailboxCalendarFolder -Identity "[email protected]:\Calendar" | Select-Object -ExpandProperty PublishedICalUrl
@joemaller
joemaller / five-horsemen-macd.rb
Last active June 24, 2025 02:54
Five Horseman Indicator
# Display in a lower subgraph
declare lower;
# Top-Five QQQ components with rankings from Invesco
input stock1 = "MSFT";
input weight1 = 8.85;
input stock2 = "NVDA";
input weight2 = 8.754;
@joemaller
joemaller / prettier-processing-instructions-bug-report.md
Created April 13, 2025 22:28
Unsubmitted bug report for Prettier handling of Processing Instructions

Input: Any Processing Instruction element, eg. <? string >?

Output modified Processing Instruction element

Expected Processing Instruction element passed through unchanged.


@joemaller
joemaller / README.md
Created April 9, 2025 17:17
Use Prettier to format PHP and HTML with a single command in VS Code.

Use Prettier to format HTML & PHP with a single VS Code command

Prettier is a fantastic tool, but doesn't natively support PHP. The Prettier PHP Plugin helps, but fully takes over formatting of PHP files and skips HTML in mixed documents.

There is a command-line solution (add --parser html), but most of the time I'm formatting on-the-fly in VS Code, so dropping out to the command line would be a huge slowdown.

Which brings up another problem: The Prettier VS Code extension hasn't worked with Prettier plugins since August 2023.

But, there's a solution to which works really well, even if it's a little slow.

@joemaller
joemaller / plane-questions.md
Created April 8, 2025 17:04
Questions I had on a plane when I couldn't search for answers. (and some answers)

Plane questions

  • Q. How to run vitest with full breakpoint debugging in vscode?

    Open JavaScript Debug terminal from the VS Code terminal dropdown menu. Run the tests normally.

  • how to increase the collapse limit for nested objects in the js console when dumping from vitest?

    This works, but it's gross:

import util from "node:util";

@joemaller
joemaller / _query-loop-patterns.md
Last active April 22, 2025 07:56
Behavior of pattern queries with the Query Loop block in the WordPress Block Editor.

Patterns are proving to be exceptionally useful, but there is some confusing, bug-like behavior with the core/query Query Loop block where patterns assigned to newly inserted blocks discard the pattern's query and fallback to the block's defaults. (as of March 2025).

  1. Insert a Query Loop block, click Choose, select pattern.
    Expectation: Use the specified pattern's query.
    Actual: The pattern specified in the query is ignored, query reverts to defaults (postType, perPage, order, etc.)

  2. Configure a Query Loop Block, then click Replace to choose a pattern
    Expectation: Either use the query in the pattern, or offer an option to replace the query?
    Actual: Existing query is preserved.
    This situation is not clear. Existing behavior makes some sense, since we've already configured the query. However there is still a query in the pattern which is being ignored.

@joemaller
joemaller / theme-json-aspect-ratios.md
Created March 21, 2025 18:49
Brief notes on setting custom Aspect Ratios for the WordPress Block Editor

WordPress 6.6 introduced support for custom Aspect Ratios for image blocks. Image Aspect Ratio options can be configured in the WordPress Block Editor by providing a list in the settings.dimensions object.

There's no easy way to remove individual aspect ratios from the list. The only options are to extend the existing list or fully replace it.

So, something like the following will produce a menu with 12 Aspect Ratio choices.

{
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 3,
@joemaller
joemaller / wrap-pagination-render_callback.php
Created March 14, 2025 16:02
Experiment for wrapping and changing the prev/next arrows in the WordPress Pagination Block
<?php
/**
* Experiment to rewrite the render_callbacks of the pagination prev/next blocks to swap the arrow for something else
*/
add_filter('register_block_type_args', __NAMESPACE__ . '\\swap_render_callback', 10, 2);
/**
* Replace the pagination-prev/next render_callback with a function which wraps the native function's return value
@joemaller
joemaller / block-editor-post-data.md
Created December 18, 2024 17:14
Quick explanation of accessing Post data in the WordPress block editor

Kind of a silly breakthrough, but I seem to have finally nailed down how to access Post data inside a custom block with useSelect. I'm not going to bother quoting the official docs, they're extensive but hard to follow. Instead, here's the chunk of code I wanted to document and remember, it exposes the full Post object to the Block Editor:

const post = useSelect(
  (select) => select("core").getEntityRecord("postType", postType, postId),
  [postId]
);

Let's walk through that, outside-in:

@joemaller
joemaller / validate-gf_token.php
Created October 10, 2024 17:09
Function to validate Gravity Forms gf_token save tokens for accessing in-progress forms
<?php
function validateGF_Token($token)
{
global $wpdb;
$gf_drafts_table = $wpdb->prefix . 'gf_draft_submissions';
$table_check = $wpdb->get_var("SHOW TABLES LIKE '{$gf_drafts_table}'");
if ($table_check !== $gf_drafts_table) {
return false;
}