Skip to content

Instantly share code, notes, and snippets.

View KeyboardCowboy's full-sized avatar

Chris Albrecht KeyboardCowboy

View GitHub Profile
@KeyboardCowboy
KeyboardCowboy / MYMODULE.module
Created May 10, 2017 17:03
Debug EntityFieldQueries in Drupal 7
<?php
/**
* Implements hook_query_TAG_alter().
*
* Add the tag 'debug' to any EFQ and this will print the query to the messages.
*
* @param \QueryAlterableInterface $query
*/
function MYMODULE_query_debug_alter(QueryAlterableInterface $query) {
@KeyboardCowboy
KeyboardCowboy / gitco.sh
Last active February 28, 2017 19:41
Shortcut to checkout a feature branch from a ticket number.
#!/usr/bin/env bash
#
# Shortcut to checkout a feature branch from a ticket number.
KEY=-1
SEARCH=$1
# Require a parameter.
if [[ -z "$SEARCH" ]]; then
echo "What are you searching for?"
@KeyboardCowboy
KeyboardCowboy / crontab
Created February 20, 2017 00:14
Have Your Mac Tell You Inspirational Quotes
# Say a quote every hour on the half hour.
30 * * * * /path/to/quotes.sh
@KeyboardCowboy
KeyboardCowboy / .gitignore
Last active August 5, 2016 16:44
Keep selected Drupal modules out of PROD automatically with Drush.
# Create a safe space for dangerous modules.
/sites/*/modules/ignored/
/docroot/sites/*/modules/ignored/
@KeyboardCowboy
KeyboardCowboy / README.md
Last active April 27, 2016 16:30
Local Drush Environment File

Add these files to your ~/.drush directory or your Drupal project.

@KeyboardCowboy
KeyboardCowboy / AwesomeCode.class.php
Last active April 25, 2016 19:24
Drupal module class.
<?php
/**
* @file
* Module class for the AwesomeCode module.
*/
/**
* Class AwesomeCode.
*
* Container class for any custom functionality in the Awesome Code module.
@KeyboardCowboy
KeyboardCowboy / commit-msg
Created April 21, 2015 23:10
Blastr Git Commit Message Hook for Jira Comments
#!/bin/bash
# INSTRUCTIONS
#
# 1. Copy .git/hooks/commit-msg.sample to .git/hooks/commit-msg
# 2. Replace the contents of commit-msg with this file
#
# Automatically add ticket numbers to commit messages using branch names.
#
# Branches should be in the format [username]-[issue #]-[short-desc]
#
@KeyboardCowboy
KeyboardCowboy / module_template.install.php
Last active April 5, 2017 18:25
Drupal Update Hook Batch Template
<?php
/**
* Template for hook_update_N() with batching.
*/
function module_template_update_7100(&$sandbox) {
$items_per_loop = 100;
// Initial setup.
if (!isset($sandbox['processed'])) {
// Load the nids to update
@KeyboardCowboy
KeyboardCowboy / rename.sh
Last active April 5, 2017 18:10
Bulk Rename Files
#!/bin/bash
# File: rename
# Author: Chris Albrecht (chris at lullabot dot com)
#
# Bulk renaming of files.
FROM=$1
TO=$2
FILTER=$3
@KeyboardCowboy
KeyboardCowboy / pre-commit
Last active February 6, 2021 18:09
Check for Drupal Debugging Statements Before Committing Code
#!/bin/bash
#
# Check for debugging statements before commiting your code.
# Place this file in the .git/hooks directory of your project.
# List of function names to search for in regex format
FUNCTIONS='dpm|kpr|qpr|console\.log'
# If any functions are found as executable, prevent the commit.
DIEONFAIL=false