Skip to content

Instantly share code, notes, and snippets.

@mrhaw
mrhaw / Move Database Files.sql
Created May 14, 2021 07:33 — forked from FlogDonkey/Move Database Files.sql
For moving Database Files off of C: drive. Accepts a single Database, or runs for *all* databases. In testing, it took about one minute for each GB of DB size, so plan accordingly accordingly. There is a list of excluded databases, allowing you to precisely target databases.
DECLARE @WorkingSQL VARCHAR(8000)
,@NewPath VARCHAR(8000) = 'G:\SQL Data\' /* Root location to move files */
,@TargetDatabase sysname = '%'; /* Specify a singular database, or % for All Databases */
SET NOCOUNT ON;
/* Sanitize path */
IF RIGHT(@NewPath, 1) <> '\'
BEGIN
SET @NewPath = @NewPath + '\';
@mrhaw
mrhaw / svg2png.js
Created August 4, 2017 07:07 — forked from gustavohenke/svg2png.js
SVG to PNG
var svg = document.querySelector( "svg" );
var svgData = new XMLSerializer().serializeToString( svg );
var canvas = document.createElement( "canvas" );
var ctx = canvas.getContext( "2d" );
var img = document.createElement( "img" );
img.setAttribute( "src", "data:image/svg+xml;base64," + btoa( svgData ) );
img.onload = function() {
@mrhaw
mrhaw / plugin.php
Created June 26, 2017 00:23 — forked from rtripault/plugin.php
Sample plugin to display the welcome screen to any new member login for the first time in MODX Revolution manager
<?php
/**
* A sample plugin to display the "welcome message" to all users, login for the first time in Revo manager
*
* @var modX $modx
* @var array $scriptProperties
* @var modPlugin $this
*
* @see modPlugin::process()
*
@mrhaw
mrhaw / Messages
Created March 21, 2017 21:17
Dashboard Widget to display the number of internal Manager messages the user has - MODX Revoluition
// Dashboard widget to show number of Manager messages
$id = $modx->user->get('id');
$output = 'No messages.';
$total = $modx->getCount('modUserMessage',array(
'recipient' => $id,
));
if($total) {
$output = 'You have ' . $total . ' messages';
$unread = $modx->getCount('modUserMessage',array(
'recipient' => $id,
@mrhaw
mrhaw / gitclean.sh
Created June 13, 2016 23:09 — forked from ericelliott/gitclean.sh
gitclean.sh - cleans merged/stale branches from origin
git remote prune origin
git branch -r --merged master | egrep -iv '(master|develop)' | sed 's/origin\///g' | xargs -n 1 git push --delete origin
@mrhaw
mrhaw / gist:ceb7d666f6a8018a2416
Last active September 4, 2015 05:17 — forked from calkan/gist:eaad0bc4458da16a72dd
Michael Hoffman's crazy bash_history backer upper on git
1 - Create a *private* GitHub/Bitbucket or similar git repo. Here I assume the repo is:
https://github.com/calkan/bash_history.git
2 - Create .history directory and initialize it for the repo:
mkdir $HOME/.history
cd $HOME/.history
git init
touch README.md
@mrhaw
mrhaw / updatefromelement.class.php
Last active August 27, 2015 21:23 — forked from Fi1osof/processor.php
modx240 fix revolution/core/model/modx/processors/element/propertyset/updatefromelement.class.php
<?php
// https://github.com/modxcms/revolution/issues/12580
include_once dirname(__FILE__).'/update.class.php';
/**
* Saves a property set
*
* @package modx
* @subpackage processors.element.propertyset
*/
@mrhaw
mrhaw / README.md
Last active August 29, 2015 14:23 — forked from sarciszewski/README.md

Aniruddh Agarwal blogged A short tour of PHP, and this is one of the negatives he identified:

Community: I know. I said that PHPs community was an advantage to it, but it is also a disadvantage, because of BAD CODE. Beginners are not taught the best practices and they go on to write bad code and distribute it, either as answers on Stack Overflow or similar websites or blog about it, which encourages other beginners to adopt those practices. There is a lot of misinformation out there, and it is very difficult to separate the good from the bad. This is perhaps the worst thing about PHP, because PHP is an entry-level language and people learning it are usually not aware of the best practices.

This is spot on!

The existence of BAD CODE being copied and pasted by newcomers is probably the biggest source of exploitable security vulnerabilities in the entire industry.

The biggest offenders are often the highest ranking search results on Google and other search eng

<?
///////////////////////////////////////
// sanitize.inc.php
// Sanitization functions for PHP
// by: Gavin Zuchlinski, Jamie Pratt, Hokkaido
// webpage: http://libox.net
// Last modified: September 27, 2003
//
// Many thanks to those on the webappsec list for helping me improve these functions
///////////////////////////////////////