Skip to content

Instantly share code, notes, and snippets.

View dongilbert's full-sized avatar
😍
Mautic WOOOO

Don Gilbert dongilbert

😍
Mautic WOOOO
View GitHub Profile

Keybase proof

I hereby claim:

  • I am dongilbert on github.
  • I am dongilbert (https://keybase.io/dongilbert) on keybase.
  • I have a public key whose fingerprint is 11E8 E1EB C4AC 096D 18B1 2D07 73BC 273C 63F2 EDFE

To claim this, I am signing this object:

@dongilbert
dongilbert / AbstractBaseEntity.php
Created April 25, 2014 20:46
AbstractBaseEntity - the solution to the problem was to wrap the constructor `$this->entityData = $data` in an `if(empty($data))` block.
<?php
namespace Entities;
abstract class AbstractBaseEntity
{
protected $entityData = [];
final public function __construct($data = [])
{
<?php
function benchmark($name, $iterations, Closure $function)
{
echo "Starting Benchmark: {$name} (".number_format($iterations)." Iterations)\n";
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$function();
}
$elapsed = microtime(true) - $start;
@dongilbert
dongilbert / WPAssetLoader.php
Created April 22, 2011 13:23
Helper function for registering and enqueueing CSS and JavaScript files within a WordPress plugin or theme.
/**
* Helper function for registering and loading scripts and styles.
* Uses regex to determine if the file is CSS or JavaScript and calls
* the proper WordPress register and enqueue functions accordingly.
*
* @name ID to register with WordPress
* @file_path Path to actual file, relative to your plugin or theme, without preceding slash.
* @for Whether this is for a plugin or a theme.
*/
function load_file($name, $file_path, $for = 'plugin') {
@dongilbert
dongilbert / create_file_hashes.php
Last active October 2, 2015 09:18
This script outputs an array of file hashes recursively for the current directory. Useful for generating hashlist for security scanning programs.
<?php
/**
* This script outputs an array of file hashes recursively for the current directory.
* Useful for generating hashlist for security scanning programs
*
*/
function recursive_md5($dir, $types = null, $recursive = true, $baseDir = '')
{
$to_ignore = array(
'.',
@dongilbert
dongilbert / geolocate.php
Created April 19, 2012 17:00
Geolocate an Address Using Google Maps via PHP
<?php
// URL Encode the address
$address = urlencode($data['storelocator']['address']);
// Get the JSON response from google. You can also get XML by changing geocode/json to geocode/xml
$geo = file_get_contents('http://maps.google.com/maps/api/geocode/json?sensor=false&address='.$address);
// Decode the results into an Object
$result = json_decode($geo);
@dongilbert
dongilbert / cycle-base.js
Created April 24, 2012 15:05
jQuery Cycle Base Container
/*
* This is a base container for
* whenever I use jQuery Cycle.
* http://jquery.malsup.com/cycle/
*
* Use this as base HTML
*
* <div id="slider">
* <div id="slides">
* <div class="slide" style="display:block">...</div>
@dongilbert
dongilbert / jconfirm.js
Created April 27, 2012 16:55
Joomla Request Confirmation Before Closing
/*
* This goes at the top of your plugin edit view,
* and will ask for confirmation before you leave.
* Be sure to replace viewname with your controller
* name, shortened. If you follow 2.5 guidelines
* with sub controllers that handel specific parts
* of the application, then this will work fine.
*/
Joomla.submitbutton = function(task) {
@dongilbert
dongilbert / remove_old_postmeta.sql
Created May 3, 2012 17:07
This SQL will delete postmeta that's still around from deleted posts.
-- Old Post Meta sometimes creeps
-- in from manually deleting revisions
-- and other things direct from the
-- database. Using this SQL below
-- you can remove the postmeta remnants
-- that have been left behind.
DELETE a
FROM wp_postmeta AS a
LEFT JOIN wp_posts AS b
@dongilbert
dongilbert / option_tree_helper.php
Created May 7, 2012 14:10
Helper functions for WP Option Tree
<?php
/**
* Paste this code in your theme's functions.php
* file and wherever you normally would call
* `get_option_tree('option-name');`, use
* `get_theme_option('option-name');` instead.
* This will pass through the already retrieved
* global $option_tree (called when your theme loads)
* and save you from several additional database
* calls on a single page request.