Skip to content

Instantly share code, notes, and snippets.

View cafuego's full-sized avatar
😢

Peter Lieverdink cafuego

😢
View GitHub Profile
@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.
hosts=$( sed -ne 's/^[ ]*[Hh][Oo][Ss][Tt]\([Nn][Aa][Mm][Ee]\)\{0,1\}[ ]*\([^#*?]*\)\(#.*\)\{0,1\}$/\2/p' .ssh/config )
@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;
}
@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 / 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);
}
_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 / 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
@cafuego
cafuego / gist:4192641
Created December 3, 2012 04:10
check serialized data
<?php
// Add yer string!
$data = '';
define('PATTERN', '/s:(\d+):"(.*?)";([Obis]):((\d+):)?([^;]+);/');
// Care not for arrays.
$blob = preg_replace('/a:\d+:{/', "\n", $data);
// Can't cope with objects.
@cafuego
cafuego / gist:3998475
Created November 2, 2012 03:08
urlamafication
<?php
$text = "Whatever stuff with URLs in it.";
$protocols = array('http', 'https', 'ftp');
$protocols = implode(':(?://)?|', $protocols) . ':(?://)?';
// Prepare domain name pattern.
// The ICANN seems to be on track towards accepting more diverse top level
// domains, so this pattern has been "future-proofed" to allow for TLDs
// of length 2-64.
#!/usr/bin/php
<?php
// define('FORMAT', 'jS F Y');
// define('FORMAT', 'YYYY/mm/dd MMM M m mmm ddd j S EEEE');
define('FORMAT', 'dd');
define('LOCALE', 'nl_NL.UTF-8');
$alpha = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z');
/**