Skip to content

Instantly share code, notes, and snippets.


Josh Koenig joshkoenig

View GitHub Profile
joshkoenig / deny_options.php
Created Apr 20, 2017
Don't serve OPTIONS responses. Ever.
View deny_options.php
// At the top of settings.php this snippit will short-cut any OPTIONS requests if you really don't want your CMS to be serving them.
// At this point you may want to set more specific response headers, etc.
die('These are not the drones you seek.');
joshkoenig / sfdc_cleanup.sql
Created Apr 8, 2017
Wipe out dupe accounts - next ETL will fill in the valid ones from SFDC
View sfdc_cleanup.sql
# Cleanup Accounts and Contacts
CREATE TEMPORARY TABLE account_cleanup_temp SELECT organization_uuid FROM _accounts_ WHERE organization_uuid IS NOT NULL GROUP BY organization_uuid HAVING COUNT(*) > 1;
DELETE a FROM _accounts_ INNER JOIN account_cleanup_temp t ON a.organization_uuid = t.organization_uuid;
DROP TABLE account_cleanup_temp;
CREATE TEMPORARY TABLE contact_cleanup_temp SELECT user_uuid FROM _contacts_ WHERE user_uuid IS NOT NULL GROUP BY user_uuid HAVING COUNT(*) > 1;
joshkoenig / object-cache.php
Last active Sep 26, 2016
object cache stub
View object-cache.php
# Engage LCache object caching system.
# We use a 'require()' here because in PHP 5.5+ changes to symlinks
# are not detected by the opcode cache, making it frustrating to deploy.
# More info:
$lcache_path = dirname( realpath( __FILE__ ) ) . '/plugins/wp-lcache/object-cache.php';
require( $lcache_path );
joshkoenig /
Last active May 23, 2018
Spider-based Benchmarking with wget
# Spiderme - quick and clean benchmarking for website performance on Pantheon.
# This script uses wget to "spider" your website to provide a good set of data
# on site performance. It will automatically bypass Pantheon's edge cache, and
# skip images, javascript, css, etc. It will also only spider links that are
# under the multidev environment you are spidering.
View gist:7c436c4f158b106eb8e2
Set-Cookie: jetpackState[message]=authorized; path=/wp-admin;
Set-Cookie: jetpackState[message]=authorized; path=/wp-admin;
Set-Cookie: jetpackState[error]=module_activation_failed; path=/wp-admin;
Set-Cookie: jetpackState[module]=after-the-deadline; path=/wp-admin;
Set-Cookie: jetpackState[reactivated_modules]=after-the-deadline; path=/wp-admin;
Set-Cookie: jetpackState[error]=module_activation_failed; path=/wp-admin;
Set-Cookie: jetpackState[module]=contact-form; path=/wp-admin;
Set-Cookie: jetpackState[reactivated_modules]=after-the-deadline%2Ccontact-form; path=/wp-admin;
Set-Cookie: jetpackState[error]=module_ac
joshkoenig / smart_auth.php
Last active Aug 29, 2015
HOWTO: http-auth in PHP
View smart_auth.php
# Here's how you can implement more nuanced logic for http auth.
# Note: this will not protect direct access to images, css, and js files.
# It will only block access to the site itself.
# It will also mean your site is not cached at the Pantheon edge at all.
# TODO: this will also block command-line access. To work around that
# we'd need to add an additional no-op check if the site is being accessed
# via Drush or WP-CLI.
joshkoenig / bgp_tweak.php
Created Apr 13, 2015
Background Process module tweakage
View bgp_tweak.php
* Remove headers we do not wish to pass on to the next request.
* @param $headers
* Headers to filter
* @return array
* Filtered headers
joshkoenig / server_name_and_port.php
Created Apr 10, 2015
View server_name_and_port.php
* Problem: there's code out there that relies on $_SERVER['SERVER_NAME'] and sometimes $_SERVER['SERVER_PORT']
* to construct urls, either to "call itself" or to create urls that are passed to third parties and expect to
* be routed back.
* This doesn't work well on Pantheon because the environmental data will be for ephemeral container data.
* In general, you don't want your code to rely on this, but if you are using some piece of contrib you may
Will pull images from a tag.
I'm using this to make a photobook of my brother in law's wedding,
but you might find it helpful for any number of other things.
from instagram.client import InstagramAPI
from pprint import pprint
import urlparse
import urllib
joshkoenig / verison_check.php
Last active Aug 29, 2015
How to make people aware of why something might not work.
View verison_check.php
# Making use of:
# The idea is you'd stick this in your core class at the top to prevent execution
# on out-dated runtime environments.
# You could use 50300 if you only care about 5.3, but it's EOL too, so...
if (!defined('PHP_VERSION_ID')) || PHP_VERSION_ID < 50400) {
# Inform users they need to upgrade their PHP version (or have their host do so)
# It'd be great if there was a common message or link to send users.
You can’t perform that action at this time.