Skip to content

Instantly share code, notes, and snippets.

View LiamKarlMitchell's full-sized avatar

Liam Mitchell LiamKarlMitchell

View GitHub Profile
@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 / 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 / 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 / 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];
}
<?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 / 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
// 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 / hibernate.cfg.xml
Created June 19, 2018 23:50
Useful Hibernate Java things
Prevent locking up forever if trying to connect when db is not available.
Set the c3p0.checkoutTime to something other than 0 so that it stops trying to connect at some point.
<property name="hibernate.c3p0.acquireRetryAttempts">2</property>
<property name="hibernate.c3p0.acquireRetryDelay">10</property>
<property name="hibernate.c3p0.checkoutTimeout">1000</property>
<property name="show_sql">false</property>
@LiamKarlMitchell
LiamKarlMitchell / DISK IOTimeout.reg
Created June 9, 2018 01:18
Windows registry tweaks.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Disk]
"TimeOutValue"=dword:00000019
"IoTimeoutValue"=dword:00000014
@LiamKarlMitchell
LiamKarlMitchell / item_category_query.sql
Last active March 24, 2018 09:59
rathena useful queries
WITH monster_drops
AS
(
SELECT id as monster_id, MVP1id AS item_id, MVP1per AS item_rate FROM mob_db
UNION
SELECT id as monster_id, MVP2id AS item_id, MVP2per AS item_rate FROM mob_db
UNION
SELECT id as monster_id, MVP3id AS item_id, MVP3per AS item_rate FROM mob_db
UNION
SELECT id as monster_id, Drop1id AS item_id, Drop1per AS item_rate FROM mob_db