Skip to content

Instantly share code, notes, and snippets.

View SamJUK's full-sized avatar

Sam James SamJUK

View GitHub Profile
@SamJUK
SamJUK / m2rjs.sh
Created July 16, 2018 19:20
Magento 2 Require JS Bundler Setup
#!/bin/bash
# Exit script if a command fails
set -e
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Setup Stuff, only needs to be run once
# Aftwards you can just run the stuff under deploy
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
@SamJUK
SamJUK / array_push_update.php
Created August 2, 2018 22:29
PHP Script to replace all 'array_push' commands width index notation '$array[] = $item' due to speed improvements
<?php
/**
* PHP Script to replace most `array_push` command usage
* in a project with index notation `$array[] = $item`
* due to speed improvements https://stackoverflow.com/a/559859
*/
function rsearch($folder, $pattern) {
$dir = new RecursiveDirectoryIterator($folder);
$ite = new RecursiveIteratorIterator($dir);
@SamJUK
SamJUK / file.sh
Created October 26, 2018 17:57
Git History
# Overview | git log --pretty=format:"%H | %ad | %s" --author="Sam James"
#for d in "~/Documents/Git Projects";
for d in ~/Desktop/*/;
do
if [ -d "$d.git" ]; then
echo " Git Project - $d";
echo "$d" >> git.log.tmp;
git --git-dir="$d.git" log --pretty=format:"%H | %ad | %s" --author="Sam James" >> git.log.tmp;
echo "\n" >> git.log.tmp;
@SamJUK
SamJUK / php
Last active December 11, 2018 00:00
Postcode Regex Testing
<?php
// Very large dataset (1762397 Lines|100 MB) so probally going to exhaust the set limit
ini_set("memory_limit", "-1");
// Download the file
$file_name = 'postcodes.zip';
$dataset_url = 'https://www.freemaptools.com/download/full-postcodes/ukpostcodes.zip';
file_put_contents($file_name, file_get_contents($dataset_url));
#!/bin/sh
# Install Instructions
# Add this file somewhere on the server(Users Home or Scripts dir would be a good place)
# Make is executable `chmod +x diskalert.sh`
# Add to crontab
# - Edit Crontab `crontab -e`
# - Add new line (Replacing cron expr and path) `0 */3 * * * /scripts/diskalert.sh`
# - Save: (ESC, Colon, w, q, enter)
#
@SamJUK
SamJUK / index.php
Created April 1, 2019 22:35
Modify another php session
<?php
session_start();
var_dump(session_id());
echo '<br>';
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
?>
<hr>
<a href="login.php"><button>Login</button></a>
@SamJUK
SamJUK / M2 Email Fix
Last active April 5, 2019 14:15
Apply following changes manually also: composer require "sashas/bug-from-email"
diff --git a/lib/internal/Magento/Framework/Mail/Message.php b/lib/internal/Magento/Framework/Mail/Message.php
index c8f0e75c5280..96566ad82b8e 100644
--- a/lib/internal/Magento/Framework/Mail/Message.php
+++ b/lib/internal/Magento/Framework/Mail/Message.php
@@ -89,10 +89,23 @@ public function getBody()
/**
* @inheritdoc
+ *
+ * @deprecated This function is missing the from name. The
<video><a href="javascript:alert(5);">a</a></video>
<p><p><audio><audio src=x onerror=alert(4)>
<p><html><audio><br /><audio src=x onerror=alert(3)></p>
<video><img src="x" onload="alert(1)"></video>
<p><audio><img src="javascript:alert(2)"></audio>
<img src=x onerror="&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041">
<IMG SRC='jav ascript:alert(`6`);'>
<img src=x onerror="javascript:alert('7')">
@SamJUK
SamJUK / script.js
Last active May 1, 2019 21:33
Generate a random string of set length
//***********
// USAGE
//***********
var string = String.random(8);
//***********
// UGLIFIED
//***********
String.prototype.constructor.random=function(r){let t,n,o="";for(;r>0;)n=r>5?5:r,o+=t=Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,n),r-=n;return o};
@SamJUK
SamJUK / script.js
Last active May 1, 2019 21:57
Generate the earliest date and latest date possible for someone of a given age
//********
//USAGE
//********
rangeFromAge(19);
//********
//UGLIFIED
//********
const rangeFromAge=e=>{let t=new Date;t.setFullYear(t.getFullYear()-e);let l=new Date(t);return l.setFullYear(l.getFullYear()-1),{earliest:Youngest,latest:Oldest}};