Skip to content

Instantly share code, notes, and snippets.

Avatar

Matt Thomas betweenbrain

View GitHub Profile
@betweenbrain
betweenbrain / wp-graphql.php
Created Aug 4, 2020
WP GraphQL register interface and to types
View wp-graphql.php
<?php
/**
* From https://wp-graphql.slack.com/archives/C3NM1M291/p1592854006371300?thread_ts=1592852289.366600&cid=C3NM1M291
*/
add_action( 'graphql_register_types', function() {
register_graphql_interface_type( 'MyNewInterface', [
'fields' => [
'myNewField' => [
'type' => 'String',
@betweenbrain
betweenbrain / error-reporting.php
Created Aug 4, 2020
WordPress error reporting
View error-reporting.php
<?php
/*
Plugin Name: PHP - Strict Error Reporting
Description: Enable strict error reporting for testing PHP.
*/
error_reporting(E_ERROR | E_WARNING | E_PARSE);
View git-recipes.md

List only SHA1 of commits in current branch.
$ git log --format=format:%H --walk-reflogs {branch name}

View geolocation-test.html
<!DOCTYPE html>
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
@betweenbrain
betweenbrain / load.php
Created Feb 15, 2020
WordPress load template part based on request (pseudo code)
View load.php
global $wp;
$current_url = add_query_arg( array(), $wp->request );
// echo '<pre>' . print_r($wp->request, true) . '</pre>';
// Add logic here:
$load = locate_template( 'archive-activity.php', true );
if ( $load ) {
// just exit if template was found and loaded
exit();
@betweenbrain
betweenbrain / vue-attribute.md
Created Nov 19, 2019
Vue alter attribute(s) of elements in component
View vue-attribute.md

Using querySelectorAll

const inits = this.$el.querySelectorAll('[ga-init]');
inits.forEach(elem => {
  elem.removeAttribute('ga-init');
  elem.removeAttribute('data-ga');
});

Using $children

View wpgraphql-hooks-filters.md
add_action(
	'graphql_return_response', function( $filtered_response, $response, $schema, $operation, $query, $variables ) {

		return $filtered_response;
	}, 10, 6
);

add_action(
	'do_graphql_request', function( $query, $operation, $variables, $params ) {
@betweenbrain
betweenbrain / mac-linux-nfs.md
Last active Mar 12, 2020
Mac backup to Linux NFS via Time Machine
View mac-linux-nfs.md

Host

$ sudo apt update
$ sudo apt install nfs-kernel-server
$ sudo mkdir /mnt/nfs -p
$ sudo chown nobody:nogroup /mnt/nfs
$ sudo chmod 777 /mnt/nfs
$ sudo nano /etc/exports
  • add something like /mnt/nfs 192.168.1.101(rw,sync,no_root_check,no_subtree_check)
@betweenbrain
betweenbrain / browser-language.js
Created Aug 12, 2019
Browser language detection
View browser-language.js
// Returns first configured browser language.
const lang = navigator.language || navigator.userLanguage;
return lang.split('-').shift();
// Returns comma separated list of languages.
let lang = (navigator.languages && 0 !== navigator.languages.length
? navigator.languages
: [navigator.language || navigator.userLanguage || 'en']);
@betweenbrain
betweenbrain / vue-route-guard-apollo-query.js
Last active Jul 10, 2019
Vue Apollo query from within Vue router route guard
View vue-route-guard-apollo-query.js
router.beforeEach((to, from, next) => {
function delay(time) {
return new Promise(resolve => {
setTimeout(function() {
resolve();
}, time);
});
}
setTimeout(async function() {
You can’t perform that action at this time.