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: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:a377c70a6fd7001718bf
Created June 2, 2014 20:23
JavaScript: HTML encoder
escapeHTML = (function() {
var entities = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;',
'/': '&#x2F;'
};
@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:1cd1bb96b677dde1a5b3
Created April 1, 2015 14:31
Plesk: Clear qmail queueu
/usr/local/psa/admin/sbin/mailqueuemng -D
@kfriend
kfriend / gist:af101ac05651cefac3f0
Created April 8, 2015 22:19
Apache: Redirect missing WP uploads to production server (via .htaccess)
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/wp-content/uploads/.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) http://www.production.com/$1 [R=301,L]
@kfriend
kfriend / gist:1c05ce5d82cb222cc0d9
Last active August 29, 2015 14:24
Remove .svn directories
find . -type d -name .svn -exec rm -rf {} \;
@kfriend
kfriend / helpers.php
Created August 16, 2015 15:01
PHP Helper Functions
<?php
// =============================================================================
// Array helpers
// =============================================================================
/**
* Array splice, associatively
*
* Splices a value into an array by targeting a key, instead of an offset.
@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:4756594
Last active December 12, 2015 10:09
Simple software version comparer. Provides ability to compare an arbitrary number of version segments. Non numberic charters not supported
<?php
function compare_versions(
$version, $compareVersion, $lookup = array('greater' => 1, 'equal' => 0, 'less' => -1)
)
{
$version = explode('.', $version);
$compareVersion = explode('.', $compareVersion);
$count = max(count($version), count($compareVersion));
@kfriend
kfriend / gist:5045040
Created February 27, 2013 04:19
12 hour select field
<?php
function select_12_hour()
{
$return = '';
for ($i = 0; $i < 24; $i++)
{
$period = ($i < 12) ? 'a.m.' : 'p.m.';