Skip to content

Instantly share code, notes, and snippets.

@davidsword
davidsword / ssbl-README.md
Last active December 30, 2020 23:40
My personal list of statuses for Slack that I use in a custom Alfred Workflow to change my Slack presense and status as well as send a ping to HomeAssistant to change a physical busy light RGB LED for my office so my family knows my current state/focus.
State Slack Status Emoji Slack Presense Busy Light
Active 🟢 🟢
In a Meeting red-dot 🟢 🔴
On Call red-dot 🟢 🔴
Red 🟢 🔴
Busy red-dot ⚪️ 🔴
BRB yellow-dot ⚪️ 🟡
Lunch yellow-dot ⚪️ 🟡
Family yellow-dot ⚪️ 🟡
<style type="text/css">
:root {
--padding: 2px;
--size: 5px;
--total: 7px;
}
body {
background: black;
padding:2px;
margin:0;
@davidsword
davidsword / x_cache_seg.php
Created November 25, 2019 18:46
Example of Cache Varients on VIP Go
<?php
/**
* Example of Cache Varients on VIP Go
*
* @see https://github.com/Automattic/vip-go-mu-plugins/blob/master/cache/examples/segmentation-maintenance-mode-bypass/vip-config.php
*/
function x_cache_seg() {
// Set the response header to let CDN know of possible varient.
header( 'Vary: X-VIP-Go-Segmentation' );
@davidsword
davidsword / darkmode-toggle.html
Created October 16, 2019 15:31
Toggle Darkmode w/ a body class
<a href='#' data-darkmode-btn>Toggle Darkmode</a>
<script type="text/javascript">
/* eslint-disable */
var darkModeBtn = document.querySelector('a[data-darkmode-btn]');
var bodyEle = document.querySelector('body');
if (localStorage.getItem('darkmode') === 'yes') {
bodyEle.classList.add("darkmode");
}
function darkmodetoggle(e) {
@davidsword
davidsword / wp-force-subdir-on-upload_dir.php
Last active September 20, 2019 04:18
WordPress - force a specific /YYYY/MM folder for media uploads.
<?php
const FORCE_UPLOAD_DIR_SUBDIR_TO = '/1990/08'; // MUST be "/YYYY/MM" format.
/**
* Force uploads to land in a specific /YYYY/MM folder.
*
* @param array $uploads information about the upload directory
* @see https://github.com/WordPress/WordPress/blob/2b92bcab85cecd819596b79b0b52f44aa4dfaffa/wp-includes/functions.php#L2223-L2239
* @return array
@davidsword
davidsword / wpcli-media-count.php
Last active October 2, 2019 19:47
WordPress WPCLI - Count Media Library by Types
<?php
/**
* Implements `media-count` command.
*/
class WPCLI_Media_Library_Count {
/**
* Get total count of all media and break down counts for each media type.
*
* ## EXAMPLES
*
@davidsword
davidsword / list-plugins.php
Last active April 8, 2019 17:16
WordPress - list all plugins in text via shortcode
<?php
/**
* List off all plugins used via `[list_plugins]` shortcode.
*
* Note that this includes inactive plugins, so keep the plugins tidy.
*
* @return string of html, list of plufins and links to their site.
*/
add_shortcode('list_plugins', function(){
@davidsword
davidsword / vs-code-settings.json
Last active February 20, 2019 00:34
VSCode settings json (20190219)
{
// App
"workbench.startupEditor": "newUntitledFile",
"workbench.settings.editor": "json",
"files.defaultLanguage": "php",
"editor.minimap.enabled": false,
"breadcrumbs.enabled": true,
// Explorer
"workbench.quickOpen.closeOnFocusLost": false,
@davidsword
davidsword / php-isset-ternary.php
Last active March 6, 2019 15:48
PHP7 - New Feature! Null coalescing operator. Quickly do isset check and defines.
<?php
/**
* The new null coalescing operator! 🎉
* @see http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op
*/
$username = $_GET['user'] ?? 'nobody';
// The old way. 🙅
$username = isset( $_GET['user'] ) ? $_GET['user'] : 'nobody';
@davidsword
davidsword / vs-code-ext.txt
Last active February 20, 2019 00:23
vs code extensions I use, my starter pack (20190219)
code --install-extension aaron-bond.better-comments
code --install-extension agauniyal.vscode-caniuse
code --install-extension ahmadawais.shades-of-purple
code --install-extension alefragnani.Bookmarks
code --install-extension alefragnani.project-manager
code --install-extension Asuka.insertnumbers
code --install-extension bmewburn.vscode-intelephense-client
code --install-extension BriteSnow.vscode-toggle-quotes
code --install-extension christian-kohler.npm-intellisense
code --install-extension claudiosanches.wpcs-whitelist-flags