Skip to content

Instantly share code, notes, and snippets.

Josh Koenig joshkoenig

Block or report user

Report or block joshkoenig

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@joshkoenig
joshkoenig / deny_options.php
Created Apr 20, 2017
Don't serve OPTIONS responses. Ever.
View deny_options.php
<?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.
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
// At this point you may want to set more specific response headers, etc.
die('These are not the drones you seek.');
}
@joshkoenig
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
joshkoenig / object-cache.php
Last active Sep 26, 2016
object cache stub
View object-cache.php
<?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: http://codinghobo.com/opcache-and-symlink-based-deployments/
#
$lcache_path = dirname( realpath( __FILE__ ) ) . '/plugins/wp-lcache/object-cache.php';
require( $lcache_path );
@joshkoenig
joshkoenig / spiderme.sh
Last active May 23, 2018
Spider-based Benchmarking with wget
View spiderme.sh
#!/bin/sh
# 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; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[message]=authorized; path=/wp-admin; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[error]=module_activation_failed; path=/wp-admin; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[module]=after-the-deadline; path=/wp-admin; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[reactivated_modules]=after-the-deadline; path=/wp-admin; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[error]=module_activation_failed; path=/wp-admin; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[module]=contact-form; path=/wp-admin; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[reactivated_modules]=after-the-deadline%2Ccontact-form; path=/wp-admin; domain=dev-quicksilver-playground.pantheonsite.io
Set-Cookie: jetpackState[error]=module_ac
@joshkoenig
joshkoenig / smart_auth.php
Last active Aug 29, 2015
HOWTO: http-auth in PHP
View smart_auth.php
<?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
joshkoenig / bgp_tweak.php
Created Apr 13, 2015
Background Process module tweakage
View bgp_tweak.php
# ADDED AN "X-.*" TO THE END TO AVOID RE-SENDING CUSTOM HEADERS.
/**
* Remove headers we do not wish to pass on to the next request.
*
* @param $headers
* Headers to filter
* @return array
* Filtered headers
*/
@joshkoenig
joshkoenig / server_name_and_port.php
Created Apr 10, 2015
SERVER_NAME and SERVER_PORT woes
View server_name_and_port.php
<?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
View instagrab.py
"""
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
joshkoenig / verison_check.php
Last active Aug 29, 2015
How to make people aware of why something might not work.
View verison_check.php
<?php
# Making use of: http://php.net/manual/en/function.phpversion.php
#
# 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.