Skip to content

Instantly share code, notes, and snippets.

View richardtape's full-sized avatar

Richard Tape richardtape

View GitHub Profile
@richardtape
richardtape / sausage
Created February 1, 2013 13:19
Start of the world's simplest html/css editor, with syntax highlighting. Copy and paste this into your browser url box and hit enter. ToDo: Add a CSS box which then applies to the iframe below. ToDo: Remove the line numbers and spurious 'X' that appears in the iframe ToDo: ? ToDo: Profit.
data:text/html;charset=utf-8, <link rel="shortcut icon" href="http://g.etfv.co/https://docs.google.com"/><title>TextEditor</title> <link rel="shortcut icon" href="http://g.etfv.co/https://docs.google.com"/> <style> html{height: 100%;} body{background: -webkit-linear-gradient(#f0f0f0, #fff); padding: 3%; height: 94%;} .paper { font: normal 12px/1.5 "Lucida Grande", arial, sans-serif; width: 50%; height: 44%; margin: 0 auto; padding: 0; position: relative; color: #444; line-height: 20px; border: 1px solid #d2d2d2; background: #fff; background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px; background: -webkit-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -moz-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -ms-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -o-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; -webkit-background-size: 100% 20px; -moz-background-size: 100% 20px;
data:text/html;charset=utf-8, <title>TextEditor</title> <link rel="shortcut icon" href="http://g.etfv.co/https://docs.google.com"/> <style> html{height: 100%;} body{background: -webkit-linear-gradient(#f0f0f0, #fff); padding: 3%; height: 94%;} .paper { font: normal 12px/1.5 "Lucida Grande", arial, sans-serif; width: 50%; height: 80%; margin: 0 auto; padding: 6px 5px 4px 42px; position: relative; color: #444; line-height: 20px; border: 1px solid #d2d2d2; background: #fff; background: -webkit-gradient(linear, 0 0, 0 100%, from(#d9eaf3), color-stop(4%, #fff)) 0 4px; background: -webkit-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -moz-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -ms-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: -o-linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; background: linear-gradient(top, #d9eaf3 0%, #fff 8%) 0 4px; -webkit-background-size: 100% 20px; -moz-background-size: 100% 20px; -ms-background-size: 100% 20px; -o-background-size: 100% 20p
@richardtape
richardtape / unrarall
Created May 14, 2014 18:43
Batch unrar from the command line in Mac OS X
# You'll need to install unrar. See: http://gotofritz.net/blog/tutorials/batch-unrar-command-line-os-x/
# Blog post: http://richardtape.com/?p=291
unrarall(){
# Get our present working directory
iamhere=`pwd`
# find all rars recursively above where we are
find "$iamhere" -name "*.rar" -exec unrar -y -ad x {} \;
@richardtape
richardtape / nginx-wpcommon.conf
Created July 24, 2014 23:30
nginx rewrite rules for composer-ised WordPress
# First two are for standard WordPress install (non-multisite)
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Remove need for /wp/
rewrite ^(/[^/]+)?(/wp-.*) /wp$2 last;
@richardtape
richardtape / install-oh-my-zsh-on-ubuntu
Created August 4, 2014 01:58
Install Oh My ZSH on Ubuntu 14.04
# Where is the location of your current shall. Useful if we need to revert
echo $0
# Install ZSH
sudo apt-get install zsh
# Instal GIT
sudo apt-get install git-core
# Install OhMyZSH
@richardtape
richardtape / subdir-loader.php
Created August 23, 2014 01:35
Allow WordPress-MU plugins to be loaded automatically from a sub directory
<?php
/**
* Plugin Name: MU plugins subdirectory loader
* Plugin URI: http://code.ctlt.ubc.ca
* Description: Enables the loading of plugins sitting in mu-plugins (as folders)
* Version: 0.1
* Author: iamfriendly, CTLT
* Author URI: http://ubc.ca/
*
@richardtape
richardtape / saved-me-hours-and-hours.sh
Created May 7, 2015 23:39
Create multiple composer.json files automatically with name of directory and push to repos
# Scenario: You have a lot (say, 200+) plugins/themes/whatevers that you need to add to a composer setup
# and none of them have composer.json files. Also, none of them are on a git repo anywhere
# Here's how I solved this problem which would have taken days to do manually
# To get git repo in each directory and then push existing code to appropriate repo
for d in ./*/ ; do (cd "$d" && git init); done
for d in ./*/ ; do (cd "$d" && git add .); done
# To allow an empty commit message, don't judge me
git config --global alias.nccommit 'commit -a --allow-empty-message -m ""'
@richardtape
richardtape / how-to-set-up-stress-free-ssl-on-os-x.md
Created March 3, 2017 22:42 — forked from jed/how-to-set-up-stress-free-ssl-on-os-x.md
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@richardtape
richardtape / why-do-i-need-a-filename.hmm
Created September 14, 2017 01:06
wp-cli with sharded databases
# Be *very* careful with this.
# In your wp-config.php file
$db_name = getenv( 'WP_CLI_DB_NAME' );
define( 'DB_NAME', ( !empty( $db_name ) ? $db_name : 'default_global' ) ); # Default often 'wpmu_global'
# Then, when calling wp-cli, if the tables you want are in a shard called prefix_3f
# And you want to grab the comments table for a site with an ID of 10175
WP_CLI_DB_NAME=prefix_3f; export WP_CLI_DB_NAME; wp db export --tables=wp_10175_comments
@richardtape
richardtape / gutenberg-sidebar-panel-and-control.js
Created October 5, 2018 00:18
Create custom gutenberg sidebar panel and control
// See richardtape.com/?p=348
/**
* Override the default edit UI to include a new block inspector control for
* adding our custom control.
*
* @param {function|Component} BlockEdit Original component.
*
* @return {string} Wrapped component.
*/