Skip to content

Instantly share code, notes, and snippets.

View jeffreyroberts's full-sized avatar

Jeffrey L. Roberts jeffreyroberts

  • PHP DevOps
  • Miami, Florida
View GitHub Profile
@jeffreyroberts
jeffreyroberts / bashrc_functions.sh
Last active December 10, 2015 12:08
Reload your bashrc's with a function, place the below function in your bashrc and then just run the command brc
# Reload bashrc function
function brc {
. /etc/bashrc
. ~/.bashrc
}
@jeffreyroberts
jeffreyroberts / Magento-Deployment-Script
Last active December 13, 2015 17:19
Magento Deployment Script
#!/bin/bash
if [ -f /tmp/git-pull.pid ]
then
exit 0
fi
cd /v2a/sites/mage/mage.base
GIT_OUTPUT=`git pull`
if [ "$GIT_OUTPUT" -eq "Already up-to-date." ]
<?php
$start_date = strtotime('3 months ago');
$start_quarter = ceil(date('m', $start_date) / 3);
$start_month = ($start_quarter * 3) - 2;
$start_year = date('Y', $start_date);
$start_timestamp = mktime(0, 0, 0, $start_month, 1, $start_year);
echo $start_timestamp;
@jeffreyroberts
jeffreyroberts / gist:5406798
Created April 17, 2013 18:58
Bash Resolve Sub Directories
resolve_sub_dirs() {
path=""
path_arg="$1"
search="$path_arg/sub-"*
for command in $search; do
if [ -d "$command" ]; then
if [ "$path" != "" ]; then
path="$command:$path"
else
#!/bin/bash
# Usage: sub mytop [-u (username)] [-p (password)]
# Summary: Watch MySQL Processes / Queries
# Help: Take a snapshot of what mysql queries are running in one second intervals
# Reference: http://akrabat.com/software/the-watch-linux-command-line-tool/
set -e
# Default Username & Password
_MYTOP_PASSWORD="-pYOURPASSWORD" # or "" for no password
#!/bin/sh
#
# <daemonname> <summary>
#
# chkconfig: <default runlevel(s)> <start> <stop>
# description: <description, split multiple lines with \
# a backslash>
### BEGIN INIT INFO
# Provides:
@jeffreyroberts
jeffreyroberts / php_load_file_into_random_queue.php
Last active December 22, 2015 03:09
PHP - load random queue from file with lines terminated by \n
function load_queues($path) {
$queuesTemp = array();
$contents = file_get_contents($path);
$contents = explode("\n", $contents);
foreach($contents as $content)
{
if(!in_array(trim($content), $queuesTemp)) {
$queuesTemp[] = trim($content);
@jeffreyroberts
jeffreyroberts / mysql_count_rows_for_each_table_in_db.sql
Last active December 23, 2015 05:49
MySQL - Count all rows per table in a database
SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = '<database_name>';
@jeffreyroberts
jeffreyroberts / mysql_count_rows_in_db.sql
Last active December 23, 2015 05:49
MySQL - Calculate total rows of all tables in a database
SELECT SUM(TABLE_ROWS)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = '<database_name>';
@jeffreyroberts
jeffreyroberts / mysql_count_rows_sql_generator.sql
Last active December 23, 2015 05:49
MySQL - Generate selects for counting rows of each table in a database
SELECT CONCAT(
'SELECT "',
table_name,
'" AS table_name, COUNT(*) AS exact_row_count FROM ',
table_schema,
'.',
table_name,
' UNION '
)
FROM INFORMATION_SCHEMA.TABLES