Skip to content

Instantly share code, notes, and snippets.

View joshkoenig's full-sized avatar

Josh Koenig joshkoenig

View GitHub Profile
@joshkoenig
joshkoenig / deny_options.php
Created April 20, 2017 22:01
Don't serve OPTIONS responses. Ever.
<?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 April 8, 2017 04:05
Wipe out dupe accounts - next ETL will fill in the valid ones from SFDC
# 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 September 26, 2016 18:49
object cache stub
<?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 22:50
Spider-based Benchmarking with wget
#!/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.
#
#
@joshkoenig
joshkoenig / gist:7c436c4f158b106eb8e2
Created March 14, 2016 19:18
JetPack SetCookie Headers
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 August 29, 2015 14:19
HOWTO: http-auth in 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 April 13, 2015 04:36
Background Process module tweakage
# 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 April 10, 2015 19:58
SERVER_NAME and SERVER_PORT woes
<?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
joshkoenig / verison_check.php
Last active August 29, 2015 14:17
How to make people aware of why something might not work.
<?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.