Skip to content

Instantly share code, notes, and snippets.

View balbuf's full-sized avatar
🍕
thinking about pizza

Stephen Beemsterboer balbuf

🍕
thinking about pizza
View GitHub Profile
@balbuf
balbuf / zenfolio-photo-downloader.js
Last active December 10, 2022 23:16 — forked from robwalkerco/zenfolio-photo-downloader.js
Zenfolio photo downloader
(async () => {
const link = document.createElement('a');
document.body.appendChild(link);
// loop through matching images
for (const image of document.querySelectorAll('.pv-inner img:first-child')) {
const path = image.style.backgroundImage.split('"')[1].replace(/-\d.jpg/, '-5.jpg');
// filename of the image
link.download = new URL(path).pathname.replace(/^.*\//, '');
// fetch the image, convert it to a data URL, set as the href of the link element
@balbuf
balbuf / videoControls.js
Created April 4, 2021 16:18
Bookmarklet to add video controls for the active video on a page
(function () {
let activeVideo;
const controls = document.createElement('div');
controls.innerHTML = `
<style>
body {
overflow: hidden;
margin: 0;
}
.input-rate {
@balbuf
balbuf / supports.scss
Created February 6, 2019 19:16
"supports" SASS mixin that provides minimal DRY benefits
@mixin supports($property-dec) {
// find position of colon in property declaration
$colon: str-index($property-dec, ':');
// extract the property
$property: str-slice($property-dec, 1, $colon - 1);
// extract the value
$value: str-slice($property-dec, $colon + 1);
// trim leading spaces
@while (str-slice($value, 1, 1) == ' ') {
$value: str-slice($value, 2);
@balbuf
balbuf / wp-import-assign-authors.js
Created January 4, 2019 21:09
Automatically populate "Assign Authors" drop downs during WordPress import
/**
Run this snippet in the JS console on the "Assign Authors"
step when running a WordPress import to automatically select
the author from the drop down that matches corresponding
author name shown from the incoming import data.
*/
$=jQuery;
$('#authors > li').each(function () {
$(this).find(`select option:contains('${$(this).find('> strong').text().replace(/^(.*) \(.+\)$/, '$1')}')`)
.prop('selected', true);
@balbuf
balbuf / ssha.sh
Created November 29, 2018 19:57
SSH with local aliases applied
# establish an ssh session with the given args and apply all of your local bash aliases
# use just like you would ssh to login to a remote shell, e.g. `ssha user@host`
function ssha() {
ssh -t "$@" 'bash --init-file <(echo '"$(printf %q "$(alias)")"')'
}
@balbuf
balbuf / tabulate-emojis.js
Created September 25, 2018 17:02
Slack tabulate emoji creators
// make sure all custom emojis are loaded, then run this in the console
console.table(Object.entries(jQuery('.p-customize_emoji_list__author').toArray().reduce((accumulator, el) => {var user = el.textContent.trim(); accumulator[user] = accumulator[user] || 0; accumulator[user]++; return accumulator;}, {})).sort((a, b) => b[1] - a[1]));
@balbuf
balbuf / debug.php
Created September 25, 2018 17:00
PHP debug function that provides basic trace info
<?php
function X($msg) {
$nameLen = 20;
$trace = debug_backtrace();
$caller = array_shift($trace);
$date = date('c');
list($ms) = explode(' ', microtime());
$line = str_pad($caller['line'], 4, '0', STR_PAD_LEFT);
$file = str_pad(substr(basename($caller['file'], '.php'), -$nameLen), $nameLen);
@balbuf
balbuf / d8-list-missing-modules.sh
Created July 19, 2018 19:06
List modules that are missing from the filesystem using drush (Drupal 8)
drush updatedb-status 2>&1 > /dev/null | sed 's/\[warning\]//g' | tr '\n' ' ' | sed 's/bootstrap[^ ]* */\n/g' | grep 'module is missing' | sed -E 's/.*: *([^ ]+) */\1/g'
# annotated version:
drush updatedb-status 2>&1 > /dev/null | # use updatedb-status because it will print an error message for each missing module but not make any changes to the drupal site; 2>&1 > /dev/null keeps only the error output
sed 's/\[warning\]//g' | # strip the string "[warning]" from the output
tr '\n' ' ' | # convert line breaks to spaces, because the lines get broken in odd spots due to an 80-character line length limit
sed 's/bootstrap[^ ]* */\n/g' | # replace the pattern "bootstrap*" with a line break, because each separate warning ends with this string
grep 'module is missing' | # filter down to only lines containing the string "module is missing"
sed -E 's/.*: *([^ ]+) */\1/g' # strip everything but the word that appears after a colon, which
@balbuf
balbuf / example.css
Last active February 6, 2019 19:22
SASS function to generate nth formulas based on repeating patterns
// example output CSS
.container :nth-of-type(5n + 1), .container :nth-of-type(5n + 2), .container :nth-of-type(5n + 3) {
background: orange;
}
.container :nth-of-type(5n + 4), .container :nth-of-type(5n + 5) {
background: blue;
}
@balbuf
balbuf / wordpress-import-update.php
Created October 15, 2016 17:54
Force the WordPress importer to update existing posts instead of skipping them
<?php
/**
* When using the WordPress Importer, update existing
* posts instead of skipping them. Updates content according
* to the import file even if the existing post was updated
* more recently.
*
* To use, drop this file into your /mu-plugins/ folder or
* copy this code into your functions.php file.