Skip to content

Instantly share code, notes, and snippets.

View rosswintle's full-sized avatar

Ross Wintle rosswintle

View GitHub Profile
@rosswintle
rosswintle / mysqlbackup.sh
Created January 10, 2018 10:38
MySQL backup all database script
#!/bin/sh
#
# This dumps all MySQL databases if you give it a root database login. You can specify the directory.
# It creates a date-and-timestamped sub-directory and individual files in there for each database.
#
HOSTNAME='localhost'
MYSQLUSER='root'
MYSQLPASS='password'
TIMESTAMP=`date +%F-%H%M%S`
@rosswintle
rosswintle / pair.php
Created January 10, 2019 22:55
Secret Santa Recursive Pairings
function make_valid_pairing( $people_to_pair, $people_yet_to_have_gifts ) {
// We made it! No more people left to pair! Return an empty array of pairings.
if (empty($people_to_pair)) {
return [];
}
// Get the first person
$person_to_pair = $people_to_pair[0];
// Get all the other people
@rosswintle
rosswintle / gdpr-resources.md
Last active January 11, 2019 16:50
My public list of GDPR resources (slightly focussed on UK-based charities and non-profits rather than businesses)
@rosswintle
rosswintle / keybindings.json
Created February 13, 2018 14:18
Better terminal toggling keybindings in VS Code
[
// Focus/unfocus terminal with ctrl+` and toggle it with ctrl+shift+`
{
"key": "ctrl+`",
"command": "workbench.action.focusActiveEditorGroup",
"when": "terminalFocus"
},
{
"key": "ctrl+`",
"command": "workbench.action.terminal.focus",
@rosswintle
rosswintle / AssetCache.php
Last active February 22, 2020 21:16
Statamic tag for my LaravelAssetCache package
<?php
/*
* Tag for my LaravelAssetCache package: https://github.com/rosswintle/laravel-asset-cache/
*
* This grabs the asset file from the specified npm package from jsdelivr.net, and caches and serves it locally
*
* Before use you'll need to:
* composer require rosswintle/laravel-asset-cache
* php artisan storage:link (in all environments)
*
@rosswintle
rosswintle / weird-wide-webring.php
Created May 19, 2020 09:32
Simple WordPress Widget for Jack McDade's Weird Wide Webring
<?php
/**
* Plugin Name: Weird Wide Webring
* Plugin URI: https://weirdwidewebring.net
* Description: A widget for displaying the Weird Wide Webring links
* Author: Ross Wintle
* Author URI: https://rosswintle.uk/
* Text Domain: weird-wide-webring
* Domain Path: /languages
* Version: 1.0.0
@rosswintle
rosswintle / .bashrc-searches
Last active October 16, 2020 14:13
Command-line (bash) code-searching functions.
# Add these to your .bashrc file for some quick and clever recursive web-dev code searching
# from the command line/terminal.
#
# Should be easy enough to add your own too.
#
# Usage is just:
#
# phprgrep <regular expression>
#
# Regular expresssions need to be escaped/quoted if you're being clever.
@rosswintle
rosswintle / functions.php
Created November 20, 2020 17:54
Filter to make WordPress YouTube oembeds use the nocookie version
<?php
add_filter('oembed_result', 'youtubeEmbedNocookieFilter', 10, 3);
function youtubeEmbedNocookieFilter(string $data, string $url, array $args)
{
return str_replace('src="https://www.youtube.com/embed', 'src="https://www.youtube-nocookie.com/embed', $data);
}
@rosswintle
rosswintle / functions.php
Created July 2, 2018 17:16
WordPress filters to make HTML password reset emails work
<?php
// adding support for html emails
// this converts ALL wp_mail emails to HTML, which messes up the password reset email
add_filter( 'wp_mail_content_type','prefix_set_content_type' );
function prefix_set_content_type() {
return "text/html";
}
// add this filter too
// this will make the password reset email compatible with the HTML format
@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);