Skip to content

Instantly share code, notes, and snippets.

View jtallant's full-sized avatar
:octocat:

Justin Tallant jtallant

:octocat:
View GitHub Profile
@jtallant
jtallant / tdd_php.md
Created July 20, 2012 21:22
TDD with PHP using PHPUnit

Instructions for Mac only.

  1. Install the latest version of PHP. I used a one liner from http://php-osx.liip.ch/. The package comes with many useful extensions (like PHPUnit) curl -s http://php-osx.liip.ch/install.sh | bash -s 5.4

  2. Add that version to your path in your bash profile export PATH="/usr/local/php5/bin:$PATH"

  3. Confirm you are using the latest version

@jtallant
jtallant / ob_flush-examples.php
Created August 4, 2012 22:40
ob_flush() php examples
<?php
/*
== ob_end_flush() ==
Flush (send) the output buffer and turn off output buffering
== ob_end_clean() ==
Clean (erase) the output buffer and turn off output buffering
== ob_get_contents() ==
@jtallant
jtallant / bootstrap-carousel-func.php
Created August 9, 2012 04:00
Output Twitter Bootstrap Carousel markup using images and excerpts from posts in a WordPress Category with PHP function
@jtallant
jtallant / conditional-nav.php
Created August 11, 2012 07:38
Using Mobile_Detector to serve a different nav
<?php
/* Serve a different nav menu for mobile devices */
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_after_header', 'child_conditional_nav' );
function child_conditional_nav() {
$detect = new Mobile_Detect();
if ( $detect->isMobile() ) {
@jtallant
jtallant / find-post-depth.php
Created August 29, 2012 20:47
Finding post depth in WordPress
function find_post_depth() {
global $post;
$parent = 0;
$level = 1;
if ($post->post_parent) {
$parent = get_post($post->post_parent);
$parents_parent = get_post($parent->post_parent);
$parent_of_parents_parent = get_post($parents_parent->post_parent);
} else {
return $level;
@jtallant
jtallant / image-checkbox.html
Created August 31, 2012 03:21
Using an image as a checkbox
<html>
<head>
<title>Checkbox</title>
<style>
input[type=checkbox] {
display:none;
}
#car + label,
@jtallant
jtallant / toggle-development-scripts-and-styles.php
Created September 2, 2012 19:33
Switching between minified and non-minified css and js files in WordPress
<?php
$jt_use_minified_files = true;
add_filter( 'stylesheet_uri', 'child_stylesheet_uri', 10, 2 );
function child_stylesheet_uri($stylesheet_uri, $stylesheet_dir_uri) {
global $jt_use_minified_files;
if ( true == $jt_use_minified_files ) {
@jtallant
jtallant / jt-related-posts.php
Created September 7, 2012 22:26
Related Posts Function for WordPress
@jtallant
jtallant / installing-node-on-centos.md
Created September 16, 2012 02:57
Installing Node on CentOS

Installing Node on CentOS

Node requires Python 2.6+

python -V make sure that is a capital V

If you are less than 2.6 then you need to install a newer version of Python but don't worry it's easy.

First off you need to recognize yum’s dependency on Python 2.4. Simply replacing this will break your passing semblance of a package manager. We will be using this later so not breaking is the preferred path. Python versions can live in relative harmony together. Download the Python source and untar it to some directory. I use /opt or ~/source for all of my non-native additions. You can choose whatever you want.

@jtallant
jtallant / sample.htaccess.txt
Created September 16, 2012 19:45
Enabling gzip and set expires headers
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript