Skip to content

Instantly share code, notes, and snippets.

View willboudle's full-sized avatar

Will Boudle willboudle

View GitHub Profile
@willboudle
willboudle / email_ssh_login.sh
Created April 19, 2023 20:14
Send email when someone ssh's into the server
#!/bin/bash
while true
do
# Search for the user string in the auth.log file and extract the relevant information
session_info=$(grep -oP 'pam_unix\(sshd:session\): session opened for user \K[^ ]+' /var/log/auth.log | grep -oP '^[^\s]+')
# If session_info is not empty, send an email with the session information
if [ -n "$session_info" ]
then
@willboudle
willboudle / m2-direct-sql.php
Last active February 17, 2021 16:37
Created with Copy to Gist
<?php
namespace [Vendor]\[Module]\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\ObjectManager;
class Data extends AbstractHelper
{
protected $resourceConnection;
public function __construct(Context $context, ResourceConnection $resourceConnection)
@willboudle
willboudle / docker-compose.yml
Created December 3, 2020 17:11
Magemodule Docker Magento
# reference: https://www.magemodule.com/all-things-magento/magento-2-tutorials/docker-magento-2-development/
version: '3'
services:
web:
image: webdevops/php-apache-dev:ubuntu-16.04
container_name: web
restart: always
user: application
environment:
- WEB_ALIAS_DOMAIN=local.domain.com
@willboudle
willboudle / gist:4fb62bac2ed895bb0172202e6288ee74
Created November 19, 2020 00:43
github-25479-json-fields-support-patch.patch
diff --git a/app/etc/di.xml b/app/etc/di.xml
index f8818de2af84..167471dbd039 100644
--- a/app/etc/di.xml
+++ b/app/etc/di.xml
@@ -1453,6 +1453,7 @@
<item name="primary" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Primary</item>
<item name="foreign" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Foreign</item>
<item name="index" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Index</item>
+ <item name="json" xsi:type="object">\Magento\Framework\Setup\Declaration\Schema\Dto\Factories\Json</item>
</argument>

Found here by Stephan Farestam

Here is a bash-only YAML parser that leverages sed and awk to parse simple yaml files:

function parse_yaml {
   local prefix=$2
   local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
   sed -ne "s|^\($s\):|\1|" \
        -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \

-e "s|^($s)($w)$s:$s(.*)$s$|\1$fs\2$fs\3|p" $1 |

@willboudle
willboudle / convert-xml-sitemap-to-html-sitemap.php
Created May 7, 2020 00:00
PHP convert XML sitemap to HTML sitemap.
<?php
$header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>HTML Sitemap</title>
</head>
<body>';
set_time_limit(400);
@willboudle
willboudle / audible-libary-to-table.js
Last active May 4, 2020 16:25
Turn Audible Library into a table
// How to use.
// Log on to Audible.com, and open up your library.
// It can be a good idea to increase the number of items per page
// and the time period you look back.
// Next, you want to run this entire file as a script on the page.
// Chrome, Firefox and Internet Explorer does this differently.
// For chrome, press F12 to open the Chrome Dev Tools, and click
// on the Console. Then paste in this whole file in the console
// window and press enter.
@willboudle
willboudle / delete-gal-img.sql
Created January 31, 2020 19:30
M2 - Delete Gallery Image Where Not like sku.jpg or Seconday Image.
DELETE
galval,
gal
FROM
catalog_product_entity_media_gallery_value galval
JOIN catalog_product_entity_media_gallery gal
ON galval.value_id = gal.value_id
WHERE galval.value_id IN
(SELECT
value_id
@willboudle
willboudle / move-gallery-img-to-main.sql
Created January 31, 2020 19:27
M2- Move Gallery Image to Main Image.
@willboudle
willboudle / images-different-than-sku.sql
Created January 31, 2020 19:25
M2 - Images are different than sku.jpg
SELECT
cpe.sku AS sku,
image.value AS main_image,
small_image.value AS main_image,
thumbnail.value AS main_image,
gal.value AS galimage
FROM
catalog_product_entity cpe
LEFT JOIN catalog_product_entity_varchar AS image
ON cpe.row_id = image.row_id