Skip to content

Instantly share code, notes, and snippets.

Neil McGann nmcgann

  • UK
Block or report user

Report or block nmcgann

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
nmcgann / s3-signer-test.php
Last active Oct 9, 2015
Amazon S3 Version 4 API request signer script
View s3-signer-test.php
//Simple example of links to files in a privately accessible s3 bucket being authorised.
//If the link is followed directly a 403 error will be returned with an xml error page.
//Instead jquery catches the click and creates an authorisation for the request assisted by
//a server that holds the access keys. The region, bucket and key are extracted and then a
//server-side authorisation query string is requested, appended to the link href and then the
//file is requested from s3.
// Bucket needs CORS turning on (for GET) and s3:GetObject permission needs to be present.
nmcgann / Dbpdo.php
Created Nov 23, 2015
PDO class to include timing and logging. Tested with mysql and mssql
View Dbpdo.php
* dbpdo.php
* Wrapper class for PDO to handle connecting to different types of db (mssql and mysql).
* Also handles mssql on both windows and linux platforms by using sqlsrv and dblib pdo drivers.
* Adds a logging and timing facility for queries and prepared statements.
* A logging function can be passed to the constructor to capture all calls to the PDO routines.
* All normal PDO and PDOStatement functions can be used with no alterations.
nmcgann / Logger.php
Created Nov 23, 2015
Simple Logging class - logs to files only.
View Logger.php
* Logger class.
* Logs to file and defaults to a /logs/ subdirectory under this script location
* This is a bit mickey-mouse as loggers go, but helpful.
// ------------------------------------------------------------------------- //
nmcgann / sql_import_class.php
Last active Dec 14, 2016
PHP SQL Import Class to read an SQL dump file and run it as SQL statements over a PDO connection
View sql_import_class.php
* Sql_import class.
* Reads a SQL file (e.g. a dump from phpmyadmin) and executes it programmatically.
* Handles procedures, triggers etc. and can load large dumps. Great for
* installer scripts to load up a db schema and populate with initial data.
* Came from:
nmcgann / install-cluster-client.config
Created Jan 13, 2016
AWS Elastic Beanstalk .ebextensions config to install Elasticache memcached cluster client (PHP 5.6)
View install-cluster-client.config
mode: "000744"
owner: root
group: root
content: |
#hide old ini
if [ -a /etc/php.d/50-memcached.ini ]
nmcgann / verify.js
Last active Feb 10, 2017
Javascript verify class based on using data atttibutes on the form inputs and submit(s). No jquery, just plain js (ES5).
View verify.js
* JS form data verification routine. Uses data attributes on the field:
* "data-verify": regex pattern that must be true for no error.
* "data-error": error message.
* "data-options": options separated by "|". First is regex parameters i/g/m as per the RegExp constructor,
* second is inversion of the test if "not", or "req" if the test must pass and a non-empty field is
* not allowed (both req and not can be used if separated by a ";" or space). Third is the name of a special test function when
* a regex isn't sufficient to do the test. Test fn must be within ValidateForm (or added to the prototype).
* If an option is blank, it can just be left empty e.g. "|req" if there are no regex params, but data-verify
* field must be present so the field is recognised as needing verifying.
nmcgann / async-scriptloader.js
Created Feb 10, 2017
Simple Asynchronous JS script loader. Not clever or modern - just works.
View async-scriptloader.js
//js async loader
var $$ = $$ || {};
$$.asyncScriptLoader = function (url) {
//get currently loaded scripts
var allScripts = document.getElementsByTagName('script'),
alreadyLoaded = false;
function onLoad(){}; //url is parameter
function onError(){}; //url is parameter
nmcgann / pdo_mysql_session.php
Last active Feb 10, 2017
PHP Mysql session handling class using PDO. Includes row locking on reads to prevent ajax race condition issues. Needs php >= 5.4.
View pdo_mysql_session.php
* Mysql DB Session class with PDO
* Uses row locking to handle concurrent ajax access
* Requires a PDO db connection to be handed to the session constructor.
* Table:
nmcgann /
Created Mar 12, 2017
Provision and fix the Vultr LAMP stack (Centos 6). Adds PhpMyAdmin and fixes the broken .htaccess files due to fcgi config (as of March 2017)
#Provision the vultr Centos6 LAMP stack as it is a bit broken as standard
#update and fetch missing things
yum update -y
yum install -y php56u-bcmath php56u-imap php56u-intl php56u-pecl-memcache
#disable opcache for development
perl -pi -e 's/^opcache.enable=1/opcache.enable=0/' /etc/php.d/10-opcache.ini
nmcgann /
Created Mar 14, 2017
bash script to install memcache on AWS lightsail LAMP stack (Mar 2017)
#install memcache on AWS lightsail bitnami
#memcache (no "d") is handy for cross platform testing as it will work on windows
#WAMP etc. where the memcached version does not appear to have a windows port)
#(lightsail lamp has the build environment gcc etc. already installed)
#memcache version
cd /root/bitnami
You can’t perform that action at this time.