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 / 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 / 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 / sha1.js
Created February 14, 2025 18:24
Tiny sha1 implementation in javascript
function sha1(r) {
var o, e, t, f, n, a = [], c = [e = 1732584193, t = 4023233417, ~e, ~t, 3285377520],
u = [], d = decodeURI(encodeURI(r)) + "€", g = d.length;
for (u[r = --g / 4 + 2 | 15] = 8 * g; ~g;) u[g >> 2] |= d.charCodeAt(g) << 8 * ~g--;
for (o = g = 0; o < r; o += 16) {
for (e = c; g < 80; e = [e[4] + (a[g] = g < 16 ? ~~u[o + g] : 2 * d | d < 0) + 1518500249 + [t & f | ~t & n, d = 341275144 + (t ^ f ^ n), 882459459 + (t & f | t & n | f & n), d + 1535694389][g++ / 5 >> 2] + ((d = e[0]) << 5 | d >>> 27), d, t << 30 | t >>> 2, f, n]) d = a[g - 3] ^ a[g - 8] ^ a[g - 14] ^ a[g - 16], t = e[1], f = e[2], n = e[3];
for (g = 5; g;) c[--g] += e[g];
}
for (d = ""; g < 40;) d += (c[g >> 3] >> 4 * (7 - g++) & 15).toString(16);
return d;
@chrishow
chrishow / post_title_condition.php
Created October 15, 2024 05:02
Use ->where('post_title', '=', 'Example Page title') as condition in Carbon Fields
class Post_Title_Condition extends Carbon_Fields\Container\Condition\Condition
{
/**
* Check if the condition is fulfilled
*
* @param array $environment
* @return bool
*/
@chrishow
chrishow / index.html
Created July 3, 2024 14:41
Octopus not SVG
<div class=container>
<ol class='in items'>
<li>Item</li>
<li>Item</li>
<li>Item</li>
<li>Item</li>
<li>Item</li>
<li>Item</li>
<li>Item</li>
@chrishow
chrishow / gist:2a4295d6d8f9736eab28cc70b5ffc746
Last active March 9, 2024 08:43
Frame rate monitor web component
const monitor = document.createElement('frame-rate');
monitor.style.position = 'fixed';
monitor.style.backgroundColor = 'white';
monitor.style.width = '84px';
monitor.style.height = '75px';
monitor.style.zIndex = '1000';
document.getElementsByTagName('body')[0].append(monitor);
@chrishow
chrishow / macro.php
Last active December 21, 2023 12:47
Case insensitive 'where' filter for Laravel Collections
<?php
/**
* $collection = collect([
* [
* 'name' => 'Chris'
* ],
* [
* 'name' => 'Monica'
* ]
@chrishow
chrishow / add_pdo_sqlsrv.sh
Created December 20, 2023 15:15
Adding pdo_sqlsrv support to Homestead for PHP8.0
#!/bin/sh
PHP_MSSQL_DRIVERS=Ubuntu2004-8.0
PHP_MSSQL_RELEASE=5.11.0
# Download and extract phpmysql drivers
sudo wget "https://github.com/Microsoft/msphpsql/releases/download/v${PHP_MSSQL_RELEASE}/${PHP_MSSQL_DRIVERS}.tar" -O - | tar -x
# Change Directory
cd $PHP_MSSQL_DRIVERS
@chrishow
chrishow / index.html
Last active November 16, 2023 13:45
Scrub on scroll video demo, https://codepen.io/chrishow/pen/BaMmyoM
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CodePen - Sticky zoom video on scroll intersection observer with scrubbing</title>
<meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="./style.css">
</head>
<body>
<!-- partial:index.partial.html -->
@chrishow
chrishow / GreenhouseJobs.php
Created October 6, 2023 12:16
Simple class to import jobs from Greenhouse.com API into WordPress
<?php
class GreenhouseJobs {
public static function get_most_recent_jobs($how_many, $categories = NULL) {
$all_jobs = static::get_jobs();
$jobs = [];