Skip to content

Instantly share code, notes, and snippets.

View tbcorr's full-sized avatar
🏠
Working from home

Tim Corr tbcorr

🏠
Working from home
  • Douglassville, PA
View GitHub Profile
// underscore template in a php file that is meant to be included on the page so that it becomes an "inline template"
<script id="template-composite-view" type="text/template">
<h1>I am a Template With Child View</h1>
<h2>Here they are.</h2>
<% if( children.length ) { %>
<% _.each(children, function(child){ %>
<div id="<%= child.cid %>" class="child-view"></div>
<% }); %>
<% } %>
</script>
@tbcorr
tbcorr / composite-view.js
Created March 7, 2016 16:17
A base Backbone.js View for Composite Views
// based very heavily on http://ianstormtaylor.com/rendering-views-in-backbonejs-isnt-always-simple/
CompositeView = Backbone.View.extend({
// assuming an inline underscrore template
template: _.template(jQuery('#template-composite-view').html())
initialize: function(){
this.children = [];
},
@tbcorr
tbcorr / short-circuit-search.php
Last active March 7, 2016 16:29
Short Circuit WordPress Search
<?php
add_filter( 'posts_request', 'tbcorr_posts_request', 10, 2 );
function tbcorr_posts_request( $request, $query ){
$is_admin = $query->query_vars['is_admin'];
$is_search = $query->query_vars['is_search'];
$is_main_query = $query->query_vars['is_main_query'];
if( $is_admin ){
@tbcorr
tbcorr / multiple-constructors.php
Last active September 24, 2015 16:56
Multiple Constructors
<?php
class MultipleConstructors {
private $prop_one; // string
private $prop_two; // int
private function __construct(){
$this->set_prop_one("");
@tbcorr
tbcorr / lazy-instantiation.php
Last active September 24, 2015 16:04
Lazy Instantiation
<?php
class LazyInstantiation {
// we can only access this static property
// through the public static getter since
// the property is private
private static $expensive_to_compute;
// public static getter