Skip to content

Instantly share code, notes, and snippets.

View LiamKarlMitchell's full-sized avatar

Liam Mitchell LiamKarlMitchell

View GitHub Profile
// Note, may have to use System.Windows.Controls
// In your method.
private void someTreeCm_SomeCommand(object sender, RoutedEventArgs e)
{
CustomTreeItem item = ((sender as MenuItem).DataContext) as CustomTreeItem;
}
// In your XAML
@LiamKarlMitchell
LiamKarlMitchell / MySQL Automated Backup Guide.md
Last active September 19, 2018 21:33
MySQL Backup and restore instructions

In the home directory make a .my.cnf file

touch ~/.my.cnf

Ensure it has your login details.

[mysqldump]
user=yourdbusername
password=yourdbpassword
<?php
// Splits a string on commas, trims whitespace and ignores empty items.
// Does not split an item with internal spaces like "some thing".
function splitter($input) {
return preg_split ('/\s*,\s*/', $input, -1, PREG_SPLIT_NO_EMPTY);
}
$labels = splitter("Oh bob, Sagget, , ,,,, ,, asdas d, a,1,2,3,4,5,");
foreach($labels as $label) {
@LiamKarlMitchell
LiamKarlMitchell / totalFileSize.php
Created August 29, 2018 21:18
A php script which read a input txt file containing files to total the size of.
<?php
// Read filenames from the input file, get their file sizes if possible and total it.
// Show the total in a human readable file size.
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
@LiamKarlMitchell
LiamKarlMitchell / totalFileSize.php
Created August 29, 2018 21:18
A php script to read a input txt file reading the contents of lines as file paths and totaling the size of those files.
<?php
// Read filenames from the input file, get their file sizes if possible and total it.
// Show the total in a human readable file size.
function human_filesize($bytes, $decimals = 2) {
$size = array('B','kB','MB','GB','TB','PB','EB','ZB','YB');
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$size[$factor];
}
@LiamKarlMitchell
LiamKarlMitchell / phpmalwaredetect.sh
Created September 4, 2018 22:07
php malware detect sh cron job send email
#!/bin/bash
# This runs the php malware finder scripts and sends an email of the log out
# First Install this project & dependencies (yara): https://github.com/nbs-system/php-malware-finder
# Modify the script as needed and set up the crontab if you wish to automate it.
#
# Example Crontab: 0 1 * * * /root/php-malware-finder/run-php-malware-finder
LOGFILE="/var/log/malwaredetect/phpmalwarefinder-$(date +'%Y-%m-%d').log";
EMAIL_MSG="Please see the log file attached.";
EMAIL_FROM="cron@someserver";
EMAIL_TO="your@email";
@LiamKarlMitchell
LiamKarlMitchell / AsyncSingleInstance.js
Last active October 12, 2018 03:27
Javascript Async Patterns
// Given an Async Function (Not a promise) this class will ensure that the run method can only run 1 instance of that async operation at a time.
class AsyncSingleInstance {
// Soon we will have private fields? https://github.com/tc39/proposal-class-fields#private-fields
//#inProgress;
//#asyncFunction;
constructor(asyncFunction) {
this.inProgress = false;
this.asyncFunction = asyncFunction;
}
@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!
@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 / 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