Skip to content

Instantly share code, notes, and snippets.

@tmbritton
tmbritton / drupal-create-block
Created June 6, 2013 19:43
Drupal Create Block
/**
* Implements hook_block_info().
*/
function YOUR_MODULE_block_info() {
$blocks = array();
$blocks['YOUR_BLOCK_ABC'] = array(
'info' => t('YOUR BLOCK NAME'),
);
return $blocks;
@tmbritton
tmbritton / validate_email.php
Created June 15, 2013 05:14
Validate Email Address - PHP
function validate_email($email) {
$filtered = filter_var($email, FILTER_VALIDATE_EMAIL);
if ($filtered == $email) {
return TRUE;
}
return FALSE;
}
@tmbritton
tmbritton / gist:5882313
Created June 28, 2013 03:35
Google News RSS url
https://news.google.com/news/feeds?um=1&ned=us&hl=en&q=rick+perry&output=rss
@tmbritton
tmbritton / drupal_add_classes
Created September 3, 2013 18:57
Drupal add classes to <body> tag based on taxonomy terms.
/**
* Implements hook_preprocess_html().
* Add classes to <body> tag based on taxonomy terms.
*/
function wfm_static_preprocess_html(&$vars) {
$node = node_load(arg(1));
if ($node && $node->type === 'page') {
if (count($node->field_body_classes) > 0) {
foreach ($node->field_body_classes[LANGUAGE_NONE] as $term) {
$machine_name = drupal_html_class($term['taxonomy_term']->name);
@tmbritton
tmbritton / body-classes
Last active December 25, 2015 19:29
Add classes to <body> tag based on metatag keywords.
/**
* Implements hook_preprocess_html().
* Add classes to <body> tag based on metatag keywords.
*
* Previous version used hook_node_view() to make keywords accessible to
* this function to avoid a node_load(). However, this hook is not available
* on mobile due to Panels so this node_load() is necessary to work for
* both themes.
*/
function hook_preprocess_html(&$vars) {
@tmbritton
tmbritton / rebuildcss.sh
Created November 20, 2013 19:46
Bash script for pre-deployment compass compilation
#!/bin/bash
#
# Rebuild CSS with Compass for both desktop and mobile theme
USER_HOME=$(eval echo ~${SUDO_USER})
DOCROOT="$USER_HOME/Sites/wfmcom/docroot/"
cd $(echo $DOCROOT/sites/all/themes/wholefoods)
pwd
THEME=$(pwd)
rm $(echo $THEME/css/style.css)
@tmbritton
tmbritton / bonus.sh
Created January 10, 2014 15:57
Quarterly bonus calculator
#!/bin/bash
#
# Bonus Calculator for WFM quarterly bonuses
read -p "What is your hourly rate? " rate
read -p "Is this a 12 or 16 week period? " weeks
read -p "What is your bonus percentage? (whole integer, not decimal) " percent
bonus=$(echo "$rate * 40 * $weeks * .$percent" | bc)
echo "Your full bonus is: $bonus"
@tmbritton
tmbritton / getData.js
Created January 28, 2014 05:35
Grab JSON from mtgjson.com, parse it and write out simplified json file of just card id and title.
/**
* @file
* Fetch card data from mtgjson.com, write it in a format
* that is more easily consumed by our application.
*/
'use strict';
var http = require('http'),
fs = require('fs');
@tmbritton
tmbritton / gist:8662903
Created January 28, 2014 05:58
Sync Wordpress files and database
#!/bin/bash
# Sync prod down to local.
rsync -chavzP --stats user@server.com:/remote/path/to/root/wp-content/uploads/ /local/path/to/root/wp-content/uploads/
echo "Creating MySQL dump"
mysqldump -P 3306 -h example.com -u username -pPASSWORD db_name > dump.sql
echo "Importing MySQL dump"
mysql -u root -proot -h 127.0.0.1 db_name < dump.sql
@tmbritton
tmbritton / casper.js test test
Created January 30, 2014 04:57
casper.js testing test
/**
* Casper.js testing test
*/
var testSuite = {
config: {
baseUrl: 'http://www.wholefoodsmarket.com',
},
googleTest: function(){