Skip to content

Instantly share code, notes, and snippets.

View joostvanveen's full-sized avatar

Joost van Veen joostvanveen

View GitHub Profile
@joostvanveen
joostvanveen / .htaccess
Last active September 10, 2023 02:37
.htaccess Security
######################################################################
## Word to the wise ##
## It is best to keep your htaccess files as clean as possible ##
## and set as many specs in your Apache config as you can. ##
## Htaccess slows down Apache. ##
## Review the entire file before use, especially the TODO sections. ##
######################################################################
Options -MultiViews
Options +FollowSymLinks
@joostvanveen
joostvanveen / csplit.sh
Created March 9, 2018 14:02
Split large SQL files into separate files for each table
## Split large SQL files into separate files for each table if every tabel starts with a 'DROP TABLE IF EXISTS' statement
csplit -k $PWD/filename.sql '/^DROP TABLE IF EXISTS .*/' '{900}'
## Split large SQL files into separate files for each table if every tabel starts with a 'CREATE TABLE' statement
csplit -k $PWD/filename.sql '/^CREATE TABLE .*/' '{900}'
@joostvanveen
joostvanveen / du.sh
Last active March 16, 2023 05:44
Get folder sizes on command line, including --max-depth, sorted by folder size desc
# Get available disk space
df -h
# Get the top 10 biggest folders in the current directory
du -h --max-depth=1 | sort -rh | head -10
# Get the top 10 biggest folders in the current directory and their first child directories
du -h --max-depth=2 | sort -rh | head -10
# Get sizes of all folders in the current directory
@joostvanveen
joostvanveen / rsync.sh
Created December 13, 2017 08:35
Crude bash script to Rsync source folder to destination folder, only certain folders and files
#!/usr/bin/env bash
# Magento 2 Deployment Script
# Author: Joost van Veen
usage="$(basename "$0") [-h] source-directory destination-directory folders-to-sync files-to-sync
Rsync folders and files from one folder to another
where:
-h show this help text
@joostvanveen
joostvanveen / linux_find_size_modified_date_and_remove_files.sh
Last active September 6, 2022 14:53
Linux commands to find all files modified older than a certain date or time, remove, find largest files or folder in a human readable way.
## NOTE: when finding file by time, use one of the following flags:
# ctime : the time a file was changed, in hours. On most systems this timestamp cannot be altered by any user, so it is fairly reliable
# atime : the time a file was last accessed, in hours. This is also set by the system.
# mtime : the modified time of a file, in hours. This can be set by any user. So if you are looking for mailcious files, never use this flag.
# cmin : same as mtime, but in minutes.
# amin : same as atime, but in minutes.
# mmin : same as mtime, but in minutes.
# Find all files in current directory changed more than 8 hours ago (480 minutes)
find $PWD -mindepth 1 -type f -cmin +480
@joostvanveen
joostvanveen / Reindex catalogrule prices in Magento 2.sh
Created November 13, 2020 06:12
Reindex catalogrule prices in Magento 2
## Reindex catalogrule prices in Magento 2
## Navigate to Magento root, e.g.:
cd ~/magento2
## Reindex the catalogrule prices
php bin/magento indexer:reindex catalogrule_product
## For this indexer to correctely index the new productprices, the
## catalogrules need to be indexed first. This usually happens
@joostvanveen
joostvanveen / delete_customers_and_orders_from_magento.sql
Last active September 16, 2021 19:07
Delete all customers and orders from Magento 1*
--
-- This query delelets all customers and orders from your
-- Magento 1.* install. Handy, if you have a bloated
-- Magento database and you need to do a bit
-- of cleaning up for use on a local machine.
--
-- Replace PREFIX_ with your current Magento table prefix.
--
-- USE AT OWN RISK. ALWAY BACKUP YOUR DATABASE FIRST.
--
@joostvanveen
joostvanveen / search_for_malicious_php_code.sh
Created October 26, 2020 12:17
Search directory for PHP files containing malicious code
## eval() is used to executed shell commands through PHP
grep -ri "eval(" $PWD --include *.php
## exec() is used to executed shell commands through PHP
grep -ri "exec(" $PWD --include *.php
## Malicious code is often obfuscated through base64 encoding
grep -ri "base64" $PWD --include *.php
## Malicious code is often obfuscated through gzip
@joostvanveen
joostvanveen / .htaccess
Last active April 22, 2021 20:12
Force SSL in .htaccess
# Force SSL, but only for a certain domain
# At the same time, redirect http non-www ad www to https://www
# Replace example\.com and example.com with your domain
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
@joostvanveen
joostvanveen / Magento 2 chcek for orders with more than one shipment or invoice.sql
Created November 13, 2020 05:59
Magento 2 chcek for orders with more than one shipment or invoice
-- Orders with more than one shipment
SELECT orders.increment_id AS ordernummer, orders.created_at, count(*) as `Aantal verzendingen` FROM sales_shipment as shipments
LEFT JOIN sales_order AS orders ON orders.entity_id = shipments.order_id
GROUP BY shipments.order_id
HAVING `Aantal verzendingen` > 1
ORDER BY orders.created_at;
-- Orders with more than 1 invoice
SELECT orders.increment_id AS ordernummer, orders.created_at, count(*) as `Aantal facturen` FROM sales_invoice as invoices
LEFT JOIN sales_order AS orders ON orders.entity_id = invoices.order_id