Skip to content

Instantly share code, notes, and snippets.

View chrishow's full-sized avatar
😄
Back to work! 🦾

Chris How chrishow

😄
Back to work! 🦾
View GitHub Profile
@chrishow
chrishow / debounce.ts
Created March 13, 2025 11:16
Tiny debounce in Typescript
// Tiny debounce
interface DebounceFunction {
(callback: (...args: any[]) => void, frequency?: number, timer?: number | null): (...args: any[]) => void;
}
export const debounce: DebounceFunction = (callback, frequency = 250, timer: number | null = null) => {
return (...args: any[]) => (
clearTimeout(timer!), (timer = setTimeout(function () {
callback();
}, frequency, ...args))
@chrishow
chrishow / compile-mcp-template-export-file.php
Created April 8, 2025 18:13
This script compiles a set of Salesforce MCP template files into a JSON object for export, suitable for the clipboard-based import into MCP.
#!/usr/bin/env php
<?php
/*
* This script compiles a set of MCP template files into a JSON object for export.
* It reads the content of each file and adds it to the JSON object.
* The output is printed to the console, you can pipe it to pbcopy then paste it
* into the MCP template editor
*
*/
@chrishow
chrishow / check-if-registered.amp
Created May 27, 2025 12:13
Simple API to check Salesforce MCP data via cloudpages
<script runat="server">
Platform.Load("core","1");
HTTPHeader.SetValue("Access-Control-Allow-Origin","*");
HTTPHeader.SetValue("Content-Type","application/json");
</script>%%[
VAR @email, @rowCount
/* Capture email & competition from URL if passed */
SET @email = RequestParameter("email")
@chrishow
chrishow / fix-svg-size-attributes.php
Last active June 1, 2025 18:49
FIx WordPress svg width and height attributes in wp_get_attachment_image_src()
<?php
add_filter( 'wp_get_attachment_image_src', function ($image, $attachment_id, $size, $icon) {
if (is_array($image) && preg_match('/\.svg$/i', $image[0]) && $image[1] <= 1) {
if(is_array($size)) {
$image[1] = $size[0];
$image[2] = $size[1];
} elseif(($xml = simplexml_load_file($image[0])) !== false) {
$attr = $xml->attributes();
$viewbox = explode(' ', $attr->viewBox);