Skip to content

Instantly share code, notes, and snippets.

View cafuego's full-sized avatar
😢

Peter Lieverdink cafuego

😢
View GitHub Profile
@cafuego
cafuego / clusterfsck
Last active December 14, 2015 03:39
Small shell script to keep an eye on xtradb cluster nodes and their statuses
#!/bin/sh
CONFIG=/etc/mysql/conf.d/xtradb-cluster.cnf
# With a syntax of gcomm://foo,bar,frog this should work eh?
NODES="$(grep ^wsrep_cluster_address ${CONFIG} | cut -d '/' -f3- | tr ',' ' ')"
if [ -z "${NODES}" ]; then
echo "Cannot find cluster nodes in config file: ${CONFIG}"
exit 1
_preprocess_node(&$variables) {
$terms = field_get_items('node', $variables['node'], 'field_topic');
$parents = taxonomy_get_parents($terms[0]['tid']);
$parent = array_shift($parents);
$variables['top_topic'] = field_view_value('node', $node, 'field_topic', array('tid' => $parent->tid));
}
@cafuego
cafuego / template.php
Created March 14, 2013 05:22
hook_preprocess_node()
function mytheme_preprocess_node(&$variables) {
$author = node_load($variables['node']->uid);
$variables['author_mail'] = check_plain($author->mail);
}
@cafuego
cafuego / htaccess
Created March 27, 2013 03:45
conditional auth_basic based on hostname
# Set password authentication on nominated hostname via the
# setenvif module.
<IfModule mod_setenvif.c>
AuthType Basic
AuthName "Enter a damn password you monkey"
AuthUserFile /some/htpasswd
Require valid-user
SetEnvIf Host .*\.example\.com$ NEED_AUTH
SetEnvIf Host .*\.example2\.com$ NEED_AUTH
@cafuego
cafuego / module.php
Created April 10, 2013 00:05
Custom module to provide static JSON map data
<?php
function mymod_menu() {
$items['view/path/that/returns/the/json] = array(
'title' => t('JSON Callback'),
'page callback' => 'mymod_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
hosts=$( sed -ne 's/^[ ]*[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\{0,1\}[ ]*\([^#*?]*\)\(#.*\)\{0,1\}$/\2/p' .ssh/config )
@cafuego
cafuego / gist:5471601
Created April 27, 2013 02:04
MySQL backup script to drop into cron.*
/etc/cron.daily/mysqldumpcron:
#!/bin/bash
#
# Create a MySQL user: GRANT SELECT, RELOAD, REPLICATION CLIENT ON *.* TO backup@localhost identified by 'password';
USER=backup
PASSWORD=password
#
# Dump the mysql and pgsql databases to a daily dump file.
@cafuego
cafuego / drush-make-wc.patch
Created May 2, 2013 00:25
Allow drush_make to keep a working-copy of a project.
diff --git a/drush_make.orig/drush_make.download.inc b/drush_make/drush_make.download.inc
index 92c68f9..2bd0bb5 100644
--- a/drush_make.orig/drush_make.download.inc
+++ b/drush_make/drush_make.download.inc
@@ -345,6 +345,7 @@ function drush_make_download_post($name, $download, $download_location) {
function drush_make_download_git($name, $download, $download_location) {
$tmp_path = drush_make_tmp();
$wc = drush_get_option('working-copy');
+ $wc = (!empty($download['working-copy'])) ? $download['working-copy'] : $wc;
@cafuego
cafuego / my.cnf
Created May 5, 2013 23:43
my.cnf for the replication slave that does backup dumps
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
@cafuego
cafuego / gist:6418333
Created September 3, 2013 00:01
mess with Drupal 7 status messages
/**
* Implements hook_preprocess_status_messages().
*
* Remove the login warning message, anon users can only see the login form anyway.
*/
function intranet_preprocess_status_messages(&$vars) {
$messages = drupal_get_messages('error');
if (!empty($messages['error'])) {
$errors = $messages['error'];
foreach ($errors as $error) {