Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Returns the total number of elements that match a given criteria.
*
* @param ElementCriteriaModel $criteria An element criteria model that defines the parameters for the elements
* we should be counting.
*
* @return int The total number of elements that match the criteria.
*/
@wesrice
wesrice / sabermetrics_batting.sql
Last active August 22, 2022 18:40
SQL Views for Sabermetrics using Lahman's Baseball Database
CREATE OR REPLACE VIEW sabermetrics_batting AS
SELECT
batting.*,
-- PA - Plate Appearances
(batting.AB + batting.BB + batting.HBP + batting.SF + batting.SH) as PA,
-- BB% - Walk Percentage (http://www.fangraphs.com/library/offense/rate-stats/)
round((batting.BB / (batting.AB + batting.BB + batting.HBP + batting.SF + batting.SH)), 3) as BBpct,
@wesrice
wesrice / AbstractEntity.php
Last active August 4, 2021 22:02
Self Validating Value Objects and Entities (Laravel Implementation)
<?php
abstract class AbstractEntity extends AbstractValueObject
{
/**
* Offset Set
*
* @param mixed $offset
* @param mixed $value
*
@wesrice
wesrice / _base.twig
Last active October 2, 2019 18:02
Sample Modular Templating for Craft CMS - Inspired by principles from https://smacss.com/.
<!DOCTYPE html>
<head>
{# Base #}
{% includeCssFile 'layouts/base/css/base.css' %}
{% includeJsFile 'layouts/base/js/base.js' %}
{# Header #}
{% includeCssFile 'modules/header/css/header.css' %}
{% includeJsFile 'modules/header/js/header.js' %}
<?php
namespace Craft;
/**
* Craft by Pixel & Tonic
*
* @package Craft
* @author Pixel & Tonic, Inc.
* @copyright Copyright (c) 2014, Pixel & Tonic, Inc.
* @license http://buildwithcraft.com/license Craft License Agreement
craft()->on('entries.saveEntry', function(Event $event) {
$entry = $event->params['entry'];
if( $event->params['entry']->sectionId == 4 ) {
craft()->request->redirect( '/admin/nameofplugin' );
}
@wesrice
wesrice / gist:7725501
Created November 30, 2013 22:36
Kyle Problem
<?php
$types = explode( ",", $_GET['types'] );
foreach( $workoutmoves AS $workoutmove ):
?>
<li>
<input class="check_box" type="checkbox" <?php in_array( $workoutmove->slug, $types ) ? 'checked' : ''; ?> value="<?php echo $workoutmove->slug; ?>"> <?php echo $workoutmove->name; ?>
</li>
<?php endforeach; ?>
@wesrice
wesrice / wp-config.php
Created September 19, 2012 15:35
Multi-environment wp-config
// Get the host
$host = $_SERVER['HTTP_HOST'];
// Define the site base
$site_base = 'example.com';
// WP subdirectory
$wp_subdirectory = '';
if( $host === 'local.' . $site_base || $host === 'localhost:8888' ){
@wesrice
wesrice / gist:2378760
Created April 13, 2012 17:49
My default wp-config.php and why WP_UPLOAD_PATH and WP_UPLOAD_URL are logical constants
<?php
/**
* The base configurations of the WordPress.
*
* This file has the following configurations: MySQL settings, Table Prefix,
* Secret Keys, WordPress Language, and ABSPATH. You can find more information
* by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
* wp-config.php} Codex page. You can get the MySQL settings from your web host.
*
* This file is used by the wp-config.php creation script during the
@wesrice
wesrice / wp-config-snippet.php
Created March 5, 2012 03:28
WordPress Database settings for working in multiple environments
<?php
/* Replace database connection information in wp-config.php */
// Get the host
$host = $_SERVER['HTTP_HOST'];
if( $host === 'local.website.com' || $host === 'localhost:8888' ){
// ** MySQL settings - You can get this info from your web host ** //