Skip to content

Instantly share code, notes, and snippets.

View james2doyle's full-sized avatar

James Doyle james2doyle

View GitHub Profile
@james2doyle
james2doyle / .phpactor.yml
Created March 22, 2024 22:25
A yaml config for phpactor that can be used in Laravel. Supports laravel-ide-helper files
indexer:
stub_paths:
- "%application_root%/_ide_helper.php"
- "%application_root%/_ide_helper_models.php"
- "%application_root%/vendor/laravel/framework/src/Illuminate/Support/Facades"
- "%application_root%/vendor/laravel/framework/src/Illuminate/Database/Eloquent"
- "%application_root%/vendor/laravel/framework/src/Illuminate/Http"
- "%application_root%/vendor/laravel/framework/src/Illuminate/Routing"
- "%application_root%/vendor/laravel/framework/src/Illuminate/View"
- "%application_root%/vendor/laravel/framework/src/Illuminate/Foundation"
@james2doyle
james2doyle / alpine.extras.js
Last active December 24, 2025 17:15
A few magic properties and directives for Alpine.js
/**
* Alpine.js magic property to confirm a change.
*
* Usage: @click="$confirm('Are you sure?').then(copied = true)"
*
* @returns {(message: string) => Promise<void>} - A function that takes the text to display as an argument.
*/
Alpine.magic('confirm', () => {
return (message) => {
return new Promise((resolve, reject) => {
@james2doyle
james2doyle / sanity-rest-api-collection.json
Created December 5, 2025 18:32
Full collection for Sanity.io REST HTTP API including Query, Assets, and comprehensive Mutation/Patch examples.
{
"info": {
"_postman_id": "b3e3e3e3-3e3e-3e3e-3e3e-3e3e3e3e3e3e",
"name": "Sanity HTTP API (Complete + Patches)",
"description": "Full collection for Sanity.io HTTP API including Query, Assets, and comprehensive Mutation/Patch examples.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Query",
@james2doyle
james2doyle / simple-json-reponse.php
Last active November 15, 2025 12:43
A simple JSON response function for PHP. Used in various PhileCMS plugins.
<?php
function json_response($code = 200, $message = null)
{
// clear the old headers
header_remove();
// set the actual code
http_response_code($code);
// set the header to make sure cache is forced
header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
@james2doyle
james2doyle / generate-deep-slug-urls.groq
Created October 10, 2025 22:06
Generate nested URLs using Groq functions in Sanity
// since the argument variable can only be referenced once, we need this function repeated
fn ex::p($p) = $p->{"c":url.current};
fn ex::pp($p) = $p->{"c": ex::p(parentPage).c};
fn ex::ppp($p) = $p->{"c": ex::pp(parentPage).c};
// will output `level-4/level-3/level-2/level-1`
// usage: { "href": ex::slug(@) }
fn ex::slug($d) = $d{"slug":array::join(
array::compact([
ex::ppp(parentPage).c,
ex::pp(parentPage).c,
@james2doyle
james2doyle / minimal.css
Created October 7, 2025 16:24
Minimal amount of CSS for a plain HTML page to look good. From https://thecascade.dev/article/least-amount-of-css/
/* @see https://thecascade.dev/article/least-amount-of-css/ */
html {
color-scheme: light dark;
}
body {
font-family: system-ui;
font-size: 1.25rem;
line-height: 1.5;
}
@james2doyle
james2doyle / print-with-chrome.sh
Created October 1, 2025 16:13
An example of printing headless with Google Chrome from the CLI
/path/to/chrome --headless \
--disable-gpu \
--no-pdf-header-footer \
--hide-scrollbars \
--print-to-pdf-margins="0,0,0,0" \
--print-to-pdf \
--window-size=1280,720 \
https://example.com
@james2doyle
james2doyle / keybinding.jsonc
Created July 9, 2025 19:18
An example of a complex keybinding in Sublime Text. This example shows you can "press [key] when selecting text to wrap it in template echo tags and a variable"
[
// press $ when selecting text to wrap it in blade echo tags and a variable
{
"keys": [
"$"
],
"command": "insert_snippet",
"args": {
"contents": "{{ \\$${0:$SELECTION} }}"
},
@james2doyle
james2doyle / levenshtein.lua
Last active June 5, 2025 17:31 — forked from Badgerati/levenshtein_algorithm.lua
An implementation of the Levenshtein distance algorithm in Lua
-- Returns the Levenshtein distance between the two given strings
-- Lower numbers are better
local function levenshtein(str1, str2)
local len1 = #str1
local len2 = #str2
local matrix = {}
local cost = 1
local min = math.min;
-- quick cut-offs to save time
@james2doyle
james2doyle / example.ionapi
Created May 1, 2024 18:46
An example on how to get an oAuth2 token from the Mingle ION API for Infor Cloudsuite
{
"ti": "AAAABBBBCCCCDDDD_ZZZ",
"cn": "Example ION File",
"dt": "11",
"ci": "AAAABBBBCCCCDDDD_ZZZ~fioUStyk923dTK4y7iXdBwVjTBYEunBtd9GpEigvBf9",
"cs": "gkBdyWByfHiOwteD-vQn9jb7pudublgsI9kW4fiPhzsOi2lFKIttCzy5ofiiyMQqgSjpuS3GRDtMHbLbj_fexq",
"iu": "https://mingle-ionapi.inforcloudsuite.com",
"pu": "https://mingle-sso.inforcloudsuite.com:443/AAAABBBBCCCCDDDD_ZZZ/as/",
"oa": "authorization.oauth2",
"ot": "token.oauth2",