Skip to content

Instantly share code, notes, and snippets.

View michaelaguiar's full-sized avatar
🎯
Focusing

Michael Aguiar michaelaguiar

🎯
Focusing
View GitHub Profile
@michaelaguiar
michaelaguiar / backup.sh
Last active January 4, 2019 20:06
Compress site and database for backup
#!/bin/bash
# Set Timestamp
time_stamp=$(date +%Y-%m-%d)
# Create Backup Directory
mkdir /backups/$time_stamp
# Backup Database
mysqldump -u root --password=DB_PASS --all-databases | gzip > /PATH/TO/SQL_DUMP.sql.gz
@michaelaguiar
michaelaguiar / README.md
Last active September 29, 2017 09:28
Device Detection

DEVICE DETECTION

Usage

Add the following to the top of your root file:

require_once('device_detect.php');
$mobile_detect = new MobileDetect;

if ($mobile_detect->isMobile()) { echo 'Mobile!'; }

@michaelaguiar
michaelaguiar / cookie.js
Last active August 29, 2015 13:56
Manage Cookies with JS
@michaelaguiar
michaelaguiar / wp_permissions.sh
Created February 12, 2014 21:34
Fix Wordpress Permissions
find ~/public_html -type d -exec chmod 755 {} \;
find ~/public_html -type f -exec chmod 644 {} \;
@michaelaguiar
michaelaguiar / case.sql
Created September 18, 2013 23:35
Case statement for MySQL
UPDATE TBL_NAME SET COL_NAME = (CASE WHEN (COL_NAME = 0) THEN 1 ELSE 0 end);
@michaelaguiar
michaelaguiar / sort_by_key.php
Created September 10, 2013 00:09
Sort an array / object by key
<?php
public function sort_by_key($key, $array, $sort_by) {
for ($i = 0; $i <= count($array) - 1; $i++) {
if (is_object($array[$i])) {
$array_item = $array[$i]->{$key};
} else {
$array_item = $array[$i][$key];
}
$sort[$i] = (isset($array_item)) ? strtolower($array_item) : '';
@michaelaguiar
michaelaguiar / breadcrumbs.php
Last active December 22, 2015 09:49
Breadcrumbs for Laravel
<div class="breadcrumbs">
<a href="/home">Home</a>
<?php
if (!URI::is('home')) {
$arrayURI = explode('/', URI::current());
foreach ($arrayURI as $key => $value) {
$url = '';
for ($i = 0; $i <= $key; $i++) {
$url .= $arrayURI[$i].'/';
}
@michaelaguiar
michaelaguiar / config
Created August 29, 2013 17:06
GIT Report for the last week
[alias]
report = "log --author=AUTHOR --since='2 sunday ago' --until='1 sunday ago' --format='%Cgreen%ci%Creset %s%Creset' --no-merges"
@michaelaguiar
michaelaguiar / guidv4.php
Created August 28, 2013 21:21
Genrate UUID v4 in PHP
<?php
function guidv4()
{
$data = openssl_random_pseudo_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0010
$data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
@michaelaguiar
michaelaguiar / functions.php
Created July 14, 2013 23:37
Woocommerce Products Per Page Selector
/* WooCommerce */
// Products per page
function woocommerce_catalog_page_ordering()
{ ?>
<form action="/shop" method="POST" name="results">
<select name="woocommerce-sort-by-columns" id="woocommerce-sort-by-columns" class="sortby" onchange="this.form.submit()">
<?php
$shopCatalog_orderby = apply_filters('woocommerce_sortby_page', array(
'' => __('Results per page', 'woocommerce'),