Skip to content

Instantly share code, notes, and snippets.


Scott Buchanan scottsb

View GitHub Profile
scottsb / gist:ebd4e00be4eb2cb18cc2
Last active August 29, 2015 14:10
All CSS Slide-Out Menu
View gist:ebd4e00be4eb2cb18cc2
<style type="text/css">
body {
font-family: helvetica, sans-serif;
margin: 0;
p {
margin: 0 0 1em;
scottsb / example.php
Last active September 11, 2015 22:01
Hack to handle multiple Exception types with a single block
View example.php
class Foo extends Exception {}
class Bar extends Exception {}
class Baz extends Exception {}
try {
throw new Foo();
} catch (Exception $e) {
switch (get_class($e)) {
case 'Foo':
scottsb / example.php
Created September 28, 2015 13:45
Comedy of Errors
View example.php
class Example {
protected $_defaultItemKey;
protected $_items;
// BUG: forces a zero-base reindex when default item is added to front of array
public function __construct($defaultItem) {
// Pretend these are loaded from the database
$this->_items = [
scottsb / gist:b67753b2c196fc33946c
Last active November 28, 2015 19:19
Bookmarklet to create Google Now reminder
View gist:b67753b2c196fc33946c
scottsb / sugit
Last active February 2, 2016 16:26
Run Git as Repo Owner
View sugit
# Execute git commands passed on command line as whatever user owns the current Git repository.
# Script can be substituted 1:1 for git in commands.
# Available under the MIT license.
sudo -u $(stat -c %U $(git rev-parse --git-dir)) git "$@"
scottsb /
Created February 24, 2016 20:25
Data to Hand Off in Digital Agency Transition
  • Credentials for site admin
  • Credentials for hosting environment
  • Credentials for domain registration & DNS
  • Admin access to any site analytics platforms
  • If the code is in version control, copy of full repository including metadata (so we can preserve commit history)
  • Explanation of how code is currently deployed to the server, including a copy of any scripts used
  • License keys & registration information for any platform third-party modules purchased
  • Any code or architecture documentation
  • List of any known outstanding defects or maintenance improvements needed
scottsb / pre-commit
Last active July 15, 2017 15:42 — forked from timsweb/pre-commit
Git hook to prevent committing xdebug_break() functions. Save as .git/hooks/pre-commit then chmod +x it. Submodules also have their own hooks folder: ".git/modules/submodule/path/here/hooks".
View pre-commit
for FILE in `git diff --cached --name-only` ; do
# Check if the file contains 'debugger'
grep -qE '^[ \t]*xdebug_break()' $FILE
if [[ $? -eq 0 ]]
echo $FILE ' contains xdebug_break()! To commit retry with --no-verify'
exit 1
scottsb /
Last active December 8, 2017 16:13
Component Library Generators for Existing Site

Component Library Generators for Existing Sites


Identify a tool for generating a living component/pattern library that can be integrated alongside a pre-existing code base. Ideally should be able to generate static HTML as part of a Grunt/Gulp job.


scottsb /
Last active April 19, 2019 10:24
Fix name of images in Magento whose names only vary by case (renaming them both in the filesystem and the database catalog). This is useful if media files need to pass through a case-insensitive filesystem, like a Mac.
# Settings
# Sanity Checks
type $MAGERUNCMD >/dev/null 2>&1 || {
echo "ERROR: This script requires the command '$MAGERUNCMD' to be executable in the current path."
scottsb /
Last active July 5, 2019 20:20
Patch for WooCommerce DPM SHA2 Response Calculation

The WooCommerce DPM plugin (v.1.8.0) has a bug in the SHA2 response calculation, causing the following error to appear to customers when they enter invalid credit card information (as well as an email to the merchant admin email):

An error occurred while trying to report this transaction to the merchant. An e-mail has been sent to the merchant informing them of the error. The following is the result of the attempt to charge your credit card.

As a quick fix, open the file class-wc-authorize-net-relay-response-handler.php and search for this bit of code:

! empty( $data[ $hash_field ] )

And replace with this: