Skip to content

Instantly share code, notes, and snippets.

@TheFrankman
TheFrankman / find-large-files.sh
Created October 19, 2017 15:36
Find files on server that are larger than a gb
sudo find / -type f -size +1000000k;
@TheFrankman
TheFrankman / disk-space-monitor.sh
Created October 18, 2017 11:24
Email disk space alerts
#!/bin/bash
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 85 ]; then
echo "VW Heritage : Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" |
mail -s "Alert: Almost out of disk space $usep%" email@example.com,email2@example.com
fi
done
@TheFrankman
TheFrankman / sql
Created October 9, 2017 11:09
Get size of all files in database
SELECT
TABLE_NAME AS `Table`,
ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
information_schema.TABLES
WHERE
TABLE_SCHEMA = "bookstore" #change to name of DB
ORDER BY
(DATA_LENGTH + INDEX_LENGTH)
DESC;
git diff -p \
| grep -E '^(diff|old mode|new mode)' \
| sed -e 's/^old/NEW/;s/^new/old/;s/^NEW/new/' \
| git apply
@TheFrankman
TheFrankman / create.php
Created July 20, 2016 18:49
Programatically create an order in Magento 2.1
<?php
/**
* @author Frank Clark
*/
namespace Vendor\Namespace\Model\Subscription\Order;
class Create
{
public function __construct(
\Magento\Framework\App\Helper\Context $context,
@TheFrankman
TheFrankman / Release.php
Last active August 16, 2017 17:22
Programatically Create Order
<?php
/**
* @author Frank Clark
*/
namespace Vendor\Namspace\Model\Subscription\Order;
use Vendor\Namspace\Model\ResourceModel\Subscriptions\CollectionFactory;
use Vendor\Namspace\Api\SubscriptionsOrdersRepositoryInterface;
use Vendor\Namspace\Model\SubscriptionsOrdersFactory;
use Vendor\Namspace\Model\Subscriptions;
@TheFrankman
TheFrankman / gist:cf74b8aad4d137b38586
Created March 16, 2015 10:40
Sanitise Magento Database
SET FOREIGN_KEY_CHECKS=0;
##############################
# SALES RELATED TABLES
##############################
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
n98-magerun.phar db:dump --force --compression="gzip" --strip="@log"
@TheFrankman
TheFrankman / Mysql Query - Find completion time of cron jobs
Last active March 13, 2017 23:07
Mysql Query - How long did cronjobs take to complete
SELECT job_code,timediff( finished_at, executed_at) as 'diff' FROM cron_schedule;
@TheFrankman
TheFrankman / Mysql Query - Consolidate duplicate emails
Last active August 29, 2015 14:11
Mysql Query - Get Duplicate Email Address - Keep the original emails
# Back up emails into new column
ALTER TABLE `customer_entity`
ADD COLUMN `old_email` VARCHAR(255) NULL;
UPDATE customer_entity SET old_email = email;
# Create two tmp tables
CREATE TEMPORARY TABLE tmp_duplicates (
entity_id INT NOT NULL
, created_at VARCHAR(255)