Skip to content

Instantly share code, notes, and snippets.

View jasonrhodes's full-sized avatar

Jason Rhodes jasonrhodes

View GitHub Profile
// D. Crockford's method for adding methods to the prototype object
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
// Add is_array function to Array, return true
Array.method('is_array', function () {
return true;
});
<?php
/*
Plugin Name: Videos
Plugin URI:
Author: Dave Rupert
Author URI: http://www.daverupert.com
Description: A custom post type that adds videos and custom taxonomies.
Version: 1.0
*/
@jasonrhodes
jasonrhodes / customobject_ex.php
Created June 1, 2011 03:09
Example of how to use the custom object class
<?php
require_once( 'customobject.php' );
$options = array(
'public' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
'menu_position' => 5,
'has_archive' => true,
'rewrite' => array( 'slug' => 'rising-profiles' )
@jasonrhodes
jasonrhodes / myplugin.php
Created August 24, 2011 17:17
A simple plugin to properly include css and javascript files into a WordPress site. * -(these files won't be minified and concatenated unless you use WP Total Cache or something similar.)
<?php
/**
* @package MyPlugin
* @version 1.0
*
* Plugin Name: MyPlugin
* Plugin URI: http://myurl.com/myplugin
* Description: A simple plugin to properly include css and javascript files into a WordPress site.
* -(these files won't be minified and concatenated unless you use WP Total Cache or something similar.)
* Author: Jason Rhodes
@jasonrhodes
jasonrhodes / arrayValueMatch.js
Created November 29, 2011 22:10
Checking for matching items in two JS arrays
function arrayValueMatch( array1, array2 ) {
var length = array1.length, match = false;
for ( i=0; i<length; i+=1 ) {
if ( array2.indexOf( array1[i] ) > -1 ) {
match = true;
break;
}
}
return match;
}

JavaScript Code Standards

Let's write better JavaScript, and the same, k?

Indentation

We always use spaces, and we always use four. Set your editor now.

function myFunction() {
@jasonrhodes
jasonrhodes / getProperty.js
Created April 6, 2012 17:40
Get a nested object property by passing a dot notation string as the property name
/**
* A function to take a string written in dot notation style, and use it to
* find a nested object property inside of an object.
*
* Useful in a plugin or module that accepts a JSON array of objects, but
* you want to let the user specify where to find various bits of data
* inside of each custom object instead of forcing a standardized
* property list.
*
* @param String nested A dot notation style parameter reference (ie "urls.small")
@jasonrhodes
jasonrhodes / uri.js
Created April 21, 2012 21:13 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.host; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
@jasonrhodes
jasonrhodes / self.static.php
Created June 5, 2012 20:49
Self vs Static in PHP
<?php
class A
{
public static $var = "I'm set in A!<br>";
public static function getStatic() {
echo static::$var;
}
public static function getSelf() {
@jasonrhodes
jasonrhodes / post-merge
Created September 20, 2012 17:10
Checks for changes in composer.json and alerts to update in a post-merge hook
#!/bin/sh
#
# To enable this hook, rename this file to "post-merge".
# We could probably run composer update here, but this is safer for now
if git diff --name-only HEAD^1 | grep composer.json >/dev/null
then
echo ' '
echo '#############################################################################'