Skip to content

Instantly share code, notes, and snippets.

View rosswintle's full-sized avatar

Ross Wintle rosswintle

View GitHub Profile
@rosswintle
rosswintle / router.php
Last active August 2, 2024 16:42
PHP web server router for WordPress
<?php
/**
* A PHP appliction router for WordPress. Can be used with command line PHP to run WordPress:
*
* php -S localhost:8000 ./router.php
*
* This is a minimal version of the router from WP-CLI's "server" command.
*/
define('ABSPATH', __DIR__ . '/');
if (preg_match('/\.(?:png|jpg|jpeg|gif|css|js|webp|aiff)$/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
@rosswintle
rosswintle / CodedInt.js
Created April 14, 2024 21:28
A small JavaScript library to help with encoding and decoding bitwise/binary data using BitInts.
/**
* A class for encoding and decoding information to and from BigInts
*/
class CodedInt {
/**
* Construct a CodedInt
*
* @param {string|number|BigInt|Boolean} x
*/
constructor(x) {
@rosswintle
rosswintle / Live.js
Created March 2, 2024 15:23
A PHP file watching watching server and JS reloading script for local development
/*
Live.js - One script closer to Designing in the Browser
Written for Handcraft.com by Martin Kool (@mrtnkl).
Updated by Ross Wintle (https://rw.omg.lol) to:
- Use EventSource for server-sent events
- Use async/await
- Use fetch instead of XMLHttpRequest for requests
- Be a JS class
- Use a hash of the HTML to check for content changes
@rosswintle
rosswintle / live.js
Created March 2, 2024 14:56
JavaScript tool to poll for changes on the server and reload page or assets - based on Live.js
/*
Live.js - One script closer to Designing in the Browser
Written for Handcraft.com by Martin Kool (@mrtnkl).
Updated by Ross Wintle (https://rw.omg.lol) to:
- Use async/await
- Use fetch instead of XMLHttpRequest
- Be a JS class
- Use a separate, project-global modified-time file to check for changes
@rosswintle
rosswintle / watch.sh
Last active March 2, 2024 14:56
File watcher shell script - for use with front-end polling script
#!/bin/bash
##
## This script watches for changes in the specified directories and runs the build
## script when changes are detected.
##
## It writes a .modified_time file to the root of the project. This contains the
## timestamp of the last modification time.
##
## This is intended to be used with a front-end script that polls for changes
@rosswintle
rosswintle / composer.json
Last active July 7, 2022 15:16
WordPress using Composer: composer.json template
{
"name": "your_organisation_or_name/your_project_name",
"repositories": [
{
"type": "composer",
"url": "https://wpackagist.org",
"only": [
"wpackagist-plugin/*",
"wpackagist-theme/*"
]
@rosswintle
rosswintle / wp-full-screen-editor-killer.user.js
Last active February 10, 2022 17:11
WordPress full-screen editor killer
// ==UserScript==
// @name WordPress Full Screen Editor killer
// @namespace http://rosswintle.uk/
// @version 0.1
// @description Auto-removes the full screen editor on WordPress sites
// @author Ross Wintle
// @match https://*/*
// @match http://*/*
// @grant none
// ==/UserScript==
@rosswintle
rosswintle / feedbin-center.js
Created February 7, 2022 22:56
Feedbin: Keep selected centered
// ==UserScript==
// @name Feedbin: Keep selected centered
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Keeps the selected item vertically centered in Feedbin
// @author Ross Wintle
// @match https://feedbin.com/
// @icon https://www.google.com/s2/favicons?domain=feedbin.com
// @grant none
// ==/UserScript==
@rosswintle
rosswintle / fathom-scriptable-widget.js
Last active November 7, 2021 20:46
Code to show daily pageviews from the Fathom API in an iOS widget using the Scriptable app
/**
* @returns {string}
*/
function getApiKey() {
return '<YOUR_API_KEY>';
}
/**
* @returns {Promise}
*/
@rosswintle
rosswintle / get_post_meta_filter.php
Last active August 7, 2021 15:56
Generic meta data filter for WordPress posts
<?php
/*
* Add a generic post meta filter that allows you to create filters like
* get_post_metadata_{$key}
*/
add_filter('get_post_metadata', 'generic _meta_filter', 100, 5);
function generic_meta_filter($value, $object_id, $meta_key, $single, $meta_type) {
remove_filter('get_post_metadata' 'generic_meta_filter', 100, 5);