Skip to content

Instantly share code, notes, and snippets.

View nmcgann's full-sized avatar

Neil McGann nmcgann

  • UK
  • 17:10 (UTC +01:00)
View GitHub Profile
@nmcgann
nmcgann / phpzip.php
Created May 7, 2017 16:29
PHP Command line zip utility. Simply zips a directory structure into an archive. No bells or whistles.
<?php
/*
* Command line zip equivalent - very simple version that just zips a directory structure completely.
* No options!
* Useful when it is needed to build e.g. a Wordpress plugin zip archive, but the dev environment
* doesn't have zip - i.e. MINGW64 as bundled with Git - has unzip, but not zip.
*/
date_default_timezone_set('UTC');
error_reporting (E_ALL);
@nmcgann
nmcgann / pub-sub.js
Created February 10, 2017 16:38
Simple JS Pub-Sub implementation. Synchronous or Asynchronous.
/*
* Simple Publish / subscribe events routine.
*
* Used to extend an object with the subscribe and publish methods.
* The return value of subscribe has a remove method that can be used
* to unsubscribe.
*
* Modifies the object directly.
*/
var $$ = $$ || {}; //This is the utility functions object used elsewhere.
@nmcgann
nmcgann / wp-db-find-and-replace.sh
Created April 13, 2017 06:30
Wordpress Database search and replace domain including serialized data.
#!/bin/bash
#wp-db-find-and-replace.sh
#
#Script to search and replace on wordpress db in .sql format e.g. to change domain url
#Works with serialized data as it recognises the php serialized format
#writes a file output
#Based on version of:
#http://wojnowski.net.pl/main/index/updating-wordpress-database-urls-part-2
#(this doesn't work as-is, but the principles are good once it is fixed)
@nmcgann
nmcgann / install-cluster-client.config
Created January 13, 2016 09:10
AWS Elastic Beanstalk .ebextensions config to install Elasticache memcached cluster client (PHP 5.6)
files:
"/home/ec2-user/install-cluster-client.sh":
mode: "000744"
owner: root
group: root
content: |
#!/bin/bash
#hide old ini
if [ -a /etc/php.d/50-memcached.ini ]
then
@nmcgann
nmcgann / sql_import_class.php
Last active May 11, 2023 09:12
PHP SQL Import Class to read an SQL dump file and run it as SQL statements over a PDO connection
<?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: http://stackoverflow.com/questions/147821/loading-sql-files-from-within-php
@nmcgann
nmcgann / IMAP_access.php
Created February 15, 2017 09:09
IMAP access class to decode imap body, fetch and assemble all the parts and attachments. Used as an utility class for processing a whole mailbox.
<?php
/**
* IMAP_access. Utility class for processing a mailbox for applications that
* want to grab the body text and do something with it e.g. create a new
* todo list item. Enough clues in there that it can be expanded to do
* a lot more if required - e.g. also grab file attachments.
*
* Based on several part-working tutorials (fixed), the PHP manual examples
* and testing on real email samples from Gmail, Thunderbird and MS outlook 2010.
* (flatten_parts is the tricky bit and was from here: