Skip to content

Instantly share code, notes, and snippets.

View dgilfoy's full-sized avatar

Daniel Gilfoy dgilfoy

  • National Center for Telehealth and Technology
  • Port Orchard, Wa
View GitHub Profile
@dgilfoy
dgilfoy / Merge Objects (deep)
Created June 11, 2014 14:42
Deep Merge of objects
Object.prototype.merge = function ( source, target ) {
var merged = (typeof target !== 'object') ? {} : target;
for ( var property in source ) {
if(source.hasOwnProperty(property)) {
var sourceProperty = source[property];
if(typeof sourceProperty === 'object') {
// call this function recursively for nested objects
merged[property] = this.merge( merged[property], sourceProperty);
continue;
}
@dgilfoy
dgilfoy / gist:6214389
Created August 12, 2013 19:42
Javascript isFunction()
function isFunction( fn ){
var getType = {};
return fn && getType.toString.call(fn) === '[object Function]';
}
@dgilfoy
dgilfoy / gist:6214307
Created August 12, 2013 19:34
Cross browser event listener
var addListener = (function() {
if (window.addEventListener) {
return function(el, ev, fn) {
el.addEventListener(ev, fn, false);
};
} else if (window.attachEvent) {
return function(el, ev, fn) {
el.attachEvent('on' + ev, function() { fn.call(el); }, false);
};
}
@dgilfoy
dgilfoy / get_terms_also_in.php
Created October 8, 2012 16:12
WordPress extension (of sorts) of get_terms(). Allows you to list the terms of a taxonomy that have posts tagged with a term of another category (just retrieves the data)
function get_terms_also_in( $list_taxonomy, $also_in_taxonomy, $with_term ){
global $wpdb;
$second_term_slug = sanitize_title_with_dashes( $with_term );
$tax1 = sanitize_title_with_dashes( $list_taxonomy );
$tax2 = sanitize_title_with_dashes( $also_in_taxonomy );
$sql = $wpdb->prepare("
SELECT cat.name, cat.slug, cat.term_id
FROM ( SELECT ac.name, ac.slug, ac.term_id, ac.term_taxonomy_id, tr.object_id
FROM {$wpdb->prefix}posts p,
( SELECT t.name, t.slug, t.term_id, tt.term_taxonomy_id FROM {$wpdb->prefix}term_taxonomy tt, {$wpdb->prefix}terms t
@dgilfoy
dgilfoy / fprint_r.php
Created May 8, 2012 22:40
Pretty Print PHP
function fprint_r() {
foreach(func_get_args() as $arg) print '<pre>' . print_r($arg, 1) . '</pre>';
}