Skip to content

Instantly share code, notes, and snippets.

View LiamKarlMitchell's full-sized avatar

Liam Mitchell LiamKarlMitchell

View GitHub Profile
@LiamKarlMitchell
LiamKarlMitchell / capitalize.js
Last active October 4, 2019 05:13
Capitalize peoples names jQuery snippet.
// Scenario:
// Users enter name in all lowercase or all uppercase it fixes the case.
// This isn't 100% suitable for all names but eh whatever!
// Attempts to resepect intentional ' and " and intentional multiple case.
$.fn.capitalize = function() {
$(this).blur(function(event) {
var box = event.target;
var txt = $(this).val();
var lc = txt.toLocaleLowerCase();
@LiamKarlMitchell
LiamKarlMitchell / PearDatabase-fix.php
Last active September 30, 2019 00:54
Fix vtiger not able to save field changes.
<?php
if ($this->dbType === 'mysql' || $this->dbType === 'mysqli') {
$this->database->Execute("SET SESSION sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
}
// Either in the mysql config or if you don't want to touch it there you can edit the include/database/PearDatabase.php and put that statement at the bottom of the function connect.
// And for setup
// Edit the
@LiamKarlMitchell
LiamKarlMitchell / Changes.md
Created September 11, 2019 23:57
Fix vTiger on mysql that requires set options.

You can change the mysql config to apply the set options.

sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

However this is not always desireable on shared hosting you don't know the follow on effects.

So far, I've found I can simply set this in the installer and the db connection class.

include/database/PearDatabase.php

@LiamKarlMitchell
LiamKarlMitchell / shell.bat
Created May 10, 2019 13:34
Set location to current directory set path enviroment variable and start a shell Windows PowerShell if available otherwise cmd Command Prompt is used.
@echo off
cd /D "%~dp0"
title Your - Shell
set PATH="%~dp0Your\bin";%PATH%
REM Start powershell if available otherwise use cmd.
for %%i in (powershell.exe) do if "%%~$path:i"=="" (cmd) else start powershell -NoLogo -NoExit -Command "& { $env:Path = \"%PATH%\" }"
@LiamKarlMitchell
LiamKarlMitchell / json-file.php
Last active April 2, 2019 22:20
Load data from and save it to a JSON file on php shutdown exit close.
<?php
namespace LiamKarlMitchell\File;
class JSONFile
{
public $filename;
private $data = array();
public function __construct($filename, $defaults = array())
{
$this->filename = $filename;
@LiamKarlMitchell
LiamKarlMitchell / refcontainer.php
Created March 1, 2019 06:20
Dumps container, referenceContainer, block and referenceBlock names and locations from Magento2 site.
<?php
$instructions = array("container", "referenceContainer", "block", "referenceBlock");
foreach ($instructions as $instruction) {
$containers = array();
$fp = fopen('debug_'.$instruction.'.txt', 'w');
$command = 'egrep -r -i --include \*.xml "<'.$instruction.'".*?"name=" *';
exec($command, $output);
@LiamKarlMitchell
LiamKarlMitchell / Find log files.md
Created November 7, 2018 20:47
Find the appropriate log files

Find log files modified in last 5 min.

find / -cmin -5 -type f -name "*.log"

For example I used this to find the Akeneo daemon log so I could tail it for debugging.

tail -100f /var/log/akeneo_daemon.err.log
@LiamKarlMitchell
LiamKarlMitchell / www.sh
Created October 31, 2018 20:43
Switch to a bash shell for www-data in web directory.
#!/bin/sh
cd /var/www/html
sudo su -s /bin/bash www-data
@LiamKarlMitchell
LiamKarlMitchell / GD2.php
Created October 31, 2018 06:40
php create square image resized to best fit
<?php
// Note: Has problem with color spaces if input image is not sRGB some color info will be dropped. Loss of saturation/vibrance may be noticable.
function create_square_image($original_file, $destination_file=NULL, $square_size = 96){
// get width and height of original image
$imagedata = getimagesize($original_file);
$original_width = $imagedata[0];
$original_height = $imagedata[1];
if($original_width > $original_height){
$new_height = $square_size;
@LiamKarlMitchell
LiamKarlMitchell / gist:686e32c5076507d54da1e0e9b7ea0da5
Created October 10, 2018 12:12
Windows 10 waking up from sleep for Windows Update Orchestrator how to fix.
powercfg -lastwake
This will show you what last woke up your PC, in my case it was Windows Updates trying to schedule a restart.
I dont care about that but could not seem to disable it even though I am logged in as an Administrator user?!
Solution download pstools from Microsoft Sysinternals
Run a cmd prompt and disable the scheduled tasks
There is probably a better way to just disable the Wake from Lan option on the task but blah!