Skip to content

Instantly share code, notes, and snippets.

View micahjon's full-sized avatar

Micah Engle-Eshleman micahjon

View GitHub Profile
@micahjon
micahjon / sentry-inline-queue.js
Last active October 22, 2021 20:27
Queue errors and replay when Sentry JS SDK loads
/* eslint-disable prefer-spread, prefer-rest-params, no-console */
/**
* Queue up Sentry.* method calls, thrown errors, and unhandled Promise rejections and
* replay them as soon as Sentry JS SDK has loaded
*
* Minify & inline this script before any other JS in the <head>
*
* Remember to add onload="onSentryLoad()" to your asynchronously loaded Sentry script, e.g.
* <script defer src="https://.../sentry-1.13.3.min.js" onload="onSentryLoad()"><script>
// ==UserScript==
// @name Convert post to Gutenberg
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Convert Wordpress classic posts to Gutenberg layout
// @author Micah Engle-Eshleman
// @include /^https:\/\/subdomain\.domain\.com\/wp-admin\/post.php\?post=\d+&action=edit/
// @grant none
// ==/UserScript==
<?php
/**
* Move image inside <p> tag above the <p> tag while preserving any link around image.
* Can be prevented by adding any attribute or whitespace to <p> tag, e.g. <p class="yolo"> or even <p >
*/
function gc_remove_p_tags_around_images($content)
{
$contentWithFixedPTags = preg_replace_callback('/<p>((?:.(?!p>))*?)(<a[^>]*>)?\s*(<img[^>]+>)(<\/a>)?(.*?)<\/p>/is', function($matches)
{
/*
@micahjon
micahjon / loadScript.js
Last active November 5, 2017 12:59
Promise-based Asynchronous Script Loader
/**
* Loads javascript file by url and saves reference to it by name, so it's not loaded again
* @param {string} name Name of js library
* @param {string} url Url to js library
* @return {promise} Resolves when library is loaded
*
* Based on example by Brad Berger: https://bradb.net/blog/promise-based-js-script-loader/
* Extended w/ global variable to keep track of previously loaded scripts.
* Removed support for loading several independent scripts at once via Promise.all()
*
@micahjon
micahjon / snippets.sh
Last active May 2, 2016 15:41
Bash Snippets
### Find & Replace
## basic examples
# replaces "urchin" with "analytics" in all files in current directory and backs up originals as .bak files
find . -type f -exec sed -i.bak "s/urchin.js/analytics.js/g" {} \;
# reverses the prior command, restoring all the original (now .bak) files
find . -name "*.bak" -exec sh -c 'mv -f $0 ${0%.bak}' {} \;