Skip to content

Instantly share code, notes, and snippets.

View kfriend's full-sized avatar

Kevin Friend kfriend

  • 742 Evergreen Terrace
View GitHub Profile
@kfriend
kfriend / gist:1cd1bb96b677dde1a5b3
Created April 1, 2015 14:31
Plesk: Clear qmail queueu
/usr/local/psa/admin/sbin/mailqueuemng -D
@kfriend
kfriend / gist:079ea35f6f496d053a5f
Last active March 5, 2016 22:44
Wordfence Falcon Homepage Workaround
<?php
// Wordfence Cache Workaround
// Apache 2.4.? - 2.4.8 contains a bug between mod_dir and mod_rewrite that prevents Wordfence's Falcon
// caching from working on the homepage, but just the homepage. This is a workaround for that issue.
$targetDomain = 'www.yourdomain.com';
// We'll need to check cookie existence to determine if the visitor is logged in. Some WP cookie names
// include a unique hash at the end, so we'll need to check by collecting all the cookie names, and
// passing them through a regex.
@kfriend
kfriend / gist:c44ff411f1f9b65ff8b2
Created November 13, 2014 14:54
Wordpress: Custom post type active nav workaround
<?php
add_filter('nav_menu_css_class', function($classes, $item) {
switch (get_query_var('post_type')) {
case 'custom_post_type_name':
if ($item->object_id == THE_ID_FOR_THE_NAV_ITEMS_TARGET_PAGE) {
$classes = array_diff($classes, array('current_page_parent'));
}
break;
}
@kfriend
kfriend / gist:810061fb3cda5a7957bc
Created June 6, 2014 18:48
VirtualBox: Enable NAT DNS Proxy (use host hosts file)
VBoxManage modifyvm "VM name" --natdnshostresolver1 on
@kfriend
kfriend / gist:a377c70a6fd7001718bf
Created June 2, 2014 20:23
JavaScript: HTML encoder
escapeHTML = (function() {
var entities = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2F;'
};
@kfriend
kfriend / gist:453a2e6d6d1260e66004
Last active August 29, 2015 14:01
Simple array proxy class. Helpful when interacting with $_POST, $_GET, etc
<?php
namespace Kfriend\Data;
use Closure;
class Proxy extends \ArrayObject
{
public function __invoke($item, $default = null)
{
@kfriend
kfriend / gist:9669711
Created March 20, 2014 17:47
PHP: Get list of all tags used in an XML document
<?php
ini_set('memory_limit', '400M');
$doc = new DOMDocument();
$doc->loadXML(file_get_contents('/path/to/xml/file.xml'));
$xpath = new DOMXpath($doc);
$nodes = $xpath->query('//*');
@kfriend
kfriend / gist:7415462
Last active December 28, 2015 00:39
.gitignore
# Annoying Files
.AppleDouble
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon^M^M
Thumbs.db
ehthumbs.db
@kfriend
kfriend / gist:4a4b36d5c3143b5feb12
Last active August 11, 2016 00:19
PHP: Very simple PDO DB wrapper
<?php
class Db
{
protected $connection;
public function __construct(PDO $connection)
{
$this->connection = $connection;
@kfriend
kfriend / Repository.php
Last active December 25, 2015 10:59
PHP: Simple repository classes
<?php
// Todo
// - Add arrary-like iterating capabilities
class Repository
{
protected $attributes = array();
public function __construct(array $attributes = array())