Skip to content

Instantly share code, notes, and snippets.

View GaryJones's full-sized avatar

Gary Jones GaryJones

View GitHub Profile
@GaryJones
GaryJones / js.js
Created January 5, 2015 12:54
Gravity Forms Countries dropdown with country codes
var countryCodes = {
'Afghanistan': '93',
'Albania': '355',
'Algeria': '213',
'American Samoa': '684',
'Andorra': '376',
'Angola': '244',
'Antigua and Barbuda': '1-268',
'Argentina': '54',
'Armenia': '374',
@GaryJones
GaryJones / gist:8430080
Created January 15, 2014 03:08
References for Why Not to Use Singleton Design Pattern
http://www.youtube.com/watch?v=-FRm3VPhseI Google's Clean Code Talks
http://blog.gordon-oheim.biz/2011-01-17-Why-Singletons-have-no-use-in-PHP/
http://sebastian-bergmann.de/archives/882-Testing-Code-That-Uses-Singletons.html
http://eamann.com/tech/making-singletons-safe-in-php/
http://hakre.wordpress.com/2012/06/10/the-missing-patterns-of-the-php-manual/#p2
http://blogs.msdn.com/b/scottdensmore/archive/2004/05/25/140827.aspx
http://www.phptherightway.com/pages/Design-Patterns.html ("You should be wary when using the singleton pattern, as by its very nature it introduces global state into your application, reducing testability.")
http://www.practicaldesignpatternsinphp.com/ ("The Singleton Pattern is perhaps the most well known - and most often misused - pattern in all of PHP design pattern development. Its simplicity, combined with its seeming benefits makes it a widely-used (and overused) pattern. The Singleton is not so much a recommended pattern, as a pattern I recommend you shy away from.")
http://www.sli
@GaryJones
GaryJones / notes.md
Last active October 24, 2023 19:12
Add PHPCS + WPCS to Sublime Text 3

Install PHP_CodeSniffer (PHPCS) via git

You can use the .phar for PHPCS, but it's easier to pull the repo down from git to then choose what version to use.

cd ~
mkdir -p code
cd code
git clone https://github.com/squizlabs/PHP_CodeSniffer.git phpcs
@GaryJones
GaryJones / .htaccess
Last active October 6, 2023 08:35
Security Headers
<IfModule mod_headers.c>
# HSTS - force redirect to HTTPS at the browser level.
# Submit for Chrome preload list at https://hstspreload.appspot.com/
# Header always set Strict-Transport-Security: "max-age=31536000; includeSubDomains; preload" env=HTTPS
# X-Xss-Protection
Header always set X-XSS-Protection "1; mode=block"
# Stop clickjacking by only allowing us to frame our own site
Header always set X-Frame-Options "SAMEORIGIN"
@GaryJones
GaryJones / phpmd.xml
Created September 12, 2014 15:04
PHPMD Ruleset for a WordPress Theme
<?xml version="1.0"?>
<ruleset name="phpmd.xml"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>PHPMD Ruleset for a WordPress Theme</description>
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag" />
<rule ref="rulesets/cleancode.xml/ElseExpression" />
<rule ref="rulesets/cleancode.xml/StaticAccess" />
@GaryJones
GaryJones / class.php
Last active September 15, 2022 14:46
Class for calculating the greatest common factor of two or more numbers.
<?php
/**
* Greatest Common Factor.
*
* @package GreatestCommonFactor
* @author Gary Jones
* @link http://code.garyjones.co.uk/greatest-common-factor-class/
* @license http://gamajo.mit-license.org/2011
*/
@GaryJones
GaryJones / gist:1258784
Created October 3, 2011 09:37 — forked from jaredatch/gist:1256954
Using the template_include filter in WordPress
<?php
add_filter( 'template_include', 'ja_template_include' );
/**
* Apply a template to all subcategories of a certain parent category.
*
* @author Jared Atchison
* @link http://www.jaredatchison.com/2011/10/02/taking-advantage-of-the-template_include-filter/
*
* @param string $template Existing path to template file
* @return string Potentially amended path to template file
@GaryJones
GaryJones / wp-prep.php
Created February 27, 2013 23:54
Refactor of wp-prep (https://github.com/jaredatch/wp-prep/blob/master/wp-prep.php). Completely untested.
<?php
/**
* WordPress Prep.
*
* Based from the WordPress Downloader
* http://www.farinspace.com/wordpress-downloader/
*
* @package wordpress-prep
* @version 1.0.1
* @author Jared Atchison
@GaryJones
GaryJones / functions.php
Last active December 23, 2021 23:10
Wrap the last Genesis breadcrumb in a span for styling.
<?php
add_filter( 'genesis_build_crumbs', 'gj_wrap_last_breadcrumb', 10, 2 );
/**
* Wrap the last Genesis breadcrumb in a span for styling.
*
* @author Gary Jones
*
* @param array $crumbs Existing HTML markup for the breadcrumbs.
*
phpcs.standard = WordPress
phpcs.tabWidth = 4
phpcs.encoding = utf-8
ftp.host = ftp.example.com
ftp.port = 21
ftp.username = username
ftp.password = password
ftp.project.dir = /subdomains/docs/httpdocs/${project.name.safe}
ftp.dir = ${ftp.project.dir}/${project.version}