Skip to content

Instantly share code, notes, and snippets.

View kadamwhite's full-sized avatar

K Adam White kadamwhite

View GitHub Profile
@kadamwhite
kadamwhite / albumArtSelector.js
Last active June 18, 2018 17:11
Paste into Dev Tools while running Plex to automatically work through your library and assign default album art.
var albumArt = (() => {
// Helpers
// (e.g. DOM shortcuts and class-checking utilities)
var qsa = ( container, selector ) => [ ...container.querySelectorAll( selector ) ];
var nodeHasClass = ( node, str ) => node.classList.toString().indexOf( str ) > -1;
var whereNodeHasClass = ( str ) => ( node ) => nodeHasClass( node, str );
var wherePropertyLike = ( obj, str ) => {
const key = Object.keys( obj ).find( key => key.indexOf( str ) > -1 );
return key ? obj[ key ] : null;
@kadamwhite
kadamwhite / .eslintrc
Created March 19, 2018 19:48
object-curly-newline-named-import-issue.js
{
"root": true,
"env": { "es6": true },
"extends": [
"eslint:recommended"
],
"parserOptions": {
"sourceType": "module"
},
"rules": {
@kadamwhite
kadamwhite / parbs-scale.md
Last active March 13, 2018 16:35 — forked from ramiabraham/parbs-scale.md
The Parbs Scale

The Parbs Scale: a Unit of Measurement for the Modern World


A Practical Means of Measuring Human-scale Physical Objects

Author: Rami Abraham
August 30, 2015

Abstract

register_meta and the REST API

In the year since 4.8, confusion about how to properly expose meta information through the REST API has been one of the most prevalend issues we've seen in support posts and tickets.

Most developers try to use register_meta with show_in_rest => true; unfortunately register_meta works on object types, not subtypes, so you cannot pass a custom post type name into register_meta like you can with register_rest_field. Worse, if you register meta for the type 'post', then that meta key is registered not just for core posts, but for every single custom post type. Meta almost never applies across all post types, so this behavior forces developers to use register_rest_field for REST API data modeling instead of taking advantage of the API's built-in meta handling.

there is no way to and this behavior makes it impossible for a developer to register meta that is specific to their single post type. and requires any REST API data modeling to use register_rest_field

@kadamwhite
kadamwhite / run-in-console.js
Last active August 1, 2017 21:23
"guess" at author mappings when importing WordPress WXR file
[...document.getElementById('authors').querySelectorAll('li')].forEach(li => {
const author = li.querySelector('strong').innerText;
const select = li.querySelector('select');
const options = [...select.querySelectorAll('option')].map(node => ({
value: node.value,
name: node.text,
}));
const match = options.reduce((match, option) => {
if (match) {
return match;
@kadamwhite
kadamwhite / ryan-api-walkthrough.md
Last active June 15, 2017 15:18
WCEU 2017 Contributor Day REST API architecture and request API lifecycle overview

REST API Contributor Day

Plan for the day

  • Improve documentation
    • Something we explain very poorly in the REST API handbook; hoping to explain it today to de-mystify
    • Handbook is what was on WP-API.org -- some stuff in there is very good and some that is out of date
    • We have some guides but they are not organized
    • We want to come up with a coherent content architecture
  • Expand the endpoints presented by the API
@kadamwhite
kadamwhite / access-vscode-extension-list.md
Last active May 8, 2019 03:08
Visual Studio Code Preferences

From Joe M, "you can get your current extensions list by typing code --list-extensions in CLI" His list:

alefragnani.Bookmarks
annsk.alignment
dbaeumer.vscode-eslint
donjayamanne.githistory
eamodio.gitlens
EditorConfig.EditorConfig
eg2.vscode-npm-script
@kadamwhite
kadamwhite / tile-and-recompose.js
Last active September 12, 2016 19:49
Take an input image, break it into tiles, then recompose the tiles into a new image (requires "convert" from image magick)
var spawn = require( 'child_process' ).spawn;
var exec = require( 'child_process' ).exec;
var path = require( 'path' );
var fs = require( 'fs' );
/**
* Get the list of files in a directory, either as a list of file and subdir
* names or a list of absolute file system paths
*
* @private
@kadamwhite
kadamwhite / movieify.js
Last active September 1, 2016 12:54
Take a directory of images output by https://github.com/jcjohnson/neural-style and convert them to a mp4
/*
RESOURCES
ffmpeg and libvpx with Homebrew https://gist.github.com/clayton/6196167
ffmpeg docs http://ffmpeg.org/ffmpeg.html
http://robotics.usc.edu/~ampereir/wordpress/?p=702
Compat https://developer.mozilla.org/en-US/docs/Web/HTML/Supported_media_formats
https://en.support.wordpress.com/accepted-filetypes/
http://easywpguide.com/wordpress-manual/adding-images-other-media/inserting-video-audio-or-other-file-type/
"Supported A/V formats include M4a, MP4, OGG, WebM, FLV, WMV, MP3, WAV and WMA files."
*/
'use strict';
var opn = require( 'opn' );
var prompt = require('prompt');
var OAuth = require( 'oauth' );
var oauth = new OAuth.OAuth(
// reqURL
'http://wpapi.loc/oauth1/request',
// accessURL