Skip to content

Instantly share code, notes, and snippets.

View betweenbrain's full-sized avatar
🎯
Focusing

Matt Thomas betweenbrain

🎯
Focusing
View GitHub Profile
@betweenbrain
betweenbrain / gist:cf019ca40071de4e0e3c
Created June 9, 2015 15:10
Joomla JDatabase return array indexed by key
$db->loadAssocList('value', 'key');
@betweenbrain
betweenbrain / gist:e7c9ccc76df5ac8efe66
Created June 3, 2015 19:41
Get random image from Joomla directory
/**
* Returns a random image from /image/homeslides/
*
* @return mixed
*/
function randomImage()
{
// Use full system path for security
$files = glob(JPATH_BASE . '/images/homeslides/*.jpg');
// Get random image
@betweenbrain
betweenbrain / README.md
Last active August 29, 2015 14:18 — forked from oodavid/README.md

Backup MySQL to Amazon S3

This is a simple way to backup your MySQL tables to Amazon S3 for a nightly backup - this is all to be done on your server :-)

Sister Document - Restore MySQL from Amazon S3 - read that next

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc

@betweenbrain
betweenbrain / gist:96b39ffb4d0ef098bfc0
Created October 17, 2014 20:37
Tuxlite for local dev
$ sudo ./domain.sh add vagrant default
@betweenbrain
betweenbrain / gist:7a2c2abfecd7fee3d963
Created August 14, 2014 21:05
MySQL Join with Subquery Selecting Joined Data from Last Month
SELECT
table1.id,
table1.firstName,
table1.lastName,
a.sales
FROM `table1`
LEFT JOIN
( SELECT
firstName,
sales,
@betweenbrain
betweenbrain / gist:b0027305656e44fe882e
Created August 14, 2014 21:04
Simple MySQL Join with Last Month Where Clause
SELECT
table1.id,
table1.firstName,
table1.lastName,
table2.sales,
table2.date
FROM `table1`
LEFT JOIN `table2` ON table1.firstName = table2.firstName
WHERE MONTH(table2.date) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH);
SELECT
table1.id,
table1.firstName,
table1.lastName,
table2.sales,
table2.date
FROM `table1`
LEFT JOIN `table2` ON table1.firstName = table2.firstName;
@betweenbrain
betweenbrain / gist:27fb11b62f05890bbbfe
Created August 5, 2014 16:49
Joomla Country Form Field
<?php defined('_JEXEC') or die;
/**
* File recipients.php
* Created 8/1/14 11:38 AM
* Author Matt Thomas | [email protected] | http://betweenbrain.com
* Support https://github.com/betweenbrain/
* Copyright Copyright (C) 2014 betweenbrain llc. All Rights Reserved.
* License GNU GPL v2 or later
*/
@betweenbrain
betweenbrain / gist:a6ed70c49f98852aae48
Created July 30, 2014 15:27
Sort Joomla items by parent
<?php
$query
->select($this->db->quoteName(array(
'title',
'id',
'parent_id')))
->select($this->db->quoteName('metadesc', 'description'))
->from($this->db->quoteName('#__categories'))
->order($this->db->quoteName('parent_id') . ' ASC')
->order($this->db->quoteName('ordering') . ' ASC');
@betweenbrain
betweenbrain / gist:e07c94110d5b843ad0bc
Last active August 29, 2015 14:04
Force group / sort Joomla items by category
<?php
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('id')))
->from($db->quoteName('#__categories'))
->where($db->quoteName('published') . ' = ' . $db->quote('1') .
' AND ' . $db->quoteName('extension') . ' = ' . $db->quote('com_content'))
->order('LFT ASC');
$db->setQuery($query);
$categories = $db->loadObjectList('id');