Skip to content

Instantly share code, notes, and snippets.

Tom Chapman chappy84

  • UK
Block or report user

Report or block chappy84

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
@chappy84
chappy84 / multiple_query_deugger.php
Last active Aug 29, 2015
PHP PDO Mysql Multiple Query Bug Debugger. Bug Page: https://bugs.php.net/bug.php?id=61613
View multiple_query_deugger.php
<?php
$myConn = new PDO(
'mysql:host=localhost;dbname=dbname',
'username',
'password'
);
$myConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$multiSqlStatement = '
INSERT INTO users (username) VALUES (:username);
@chappy84
chappy84 / tidy-directory.php
Created May 20, 2012
Convert all X/HTML files in a folder to valid X/HTML using libtidy via PHP
View tidy-directory.php
<?php
defined('TIDYDIR_EXTENSION') || define('TIDYDIR_EXTENSION', 'html');
function tidyDir($directory) {
$htmlFiles = glob($directory.DIRECTORY_SEPARATOR.'*.'.TIDYDIR_EXTENSION);
$filenameRegEx = '#^(.+?)\.([^\.]+?)$#';
$htmlTidy = new tidy();
foreach ($htmlFiles as $entry) {
if (preg_match($filenameRegEx, $entry, $matches)) {
$filename = $matches[1];
$extension = $matches[2];
@chappy84
chappy84 / mongod
Created Dec 28, 2012
Default install of MongoDB 2.2.2 installed from source running in systemd on Fedora 15
View mongod
OPTIONS="--quiet -f /etc/mongod.conf"
View convert_assertions_etc.sh
#!/bin/sh
# Usage: convert_assertions.sh file1 file2 ...
perl -i -p \
-e 's/assertEquals?/assertEquals/g;' \
-e 's/assertNotEquals?/assertNotEquals/g;' \
-e 's/assertPattern/assertRegExp/g;' \
-e 's/assertIdentical/assertSame/g;' \
-e 's/assertNotIdentical/assertNotSame/g;' \
-e 's/assertNoPattern/assertNotRegExp/g;' \
-e 's/assertReference/assertSame/g;' \
@chappy84
chappy84 / date_iso.php
Last active Dec 11, 2015
Format a local time/date using an ISO Format
View date_iso.php
<?php
function date_iso($format, $timestamp = null)
{
if ($timestamp === null) {
$timestamp = time();
}
$convert = array(
'a' => 'A' , 'B' => 'B', 'D' => 'z', 'ddd' => 't', 'dd' => 'd', 'd' => 'j',
@chappy84
chappy84 / githubStarred.php
Last active Nov 20, 2016
Github Starred Dates - displays when you starred repos, which seems to have disappeared from GitHub's UI :(
View githubStarred.php
<?php
function errorAndDie($message) {
echo $message . PHP_EOL;
die(1);
}
$url = 'https://api.github.com/user/starred';
do {
@chappy84
chappy84 / mysql_pivot.sql
Created Aug 31, 2014
MySQL Pivot Stored Procedure
View mysql_pivot.sql
DROP PROCEDURE IF EXISTS pivot_user_preferences;
DELIMITER $$
CREATE PROCEDURE pivot_user_preferences(IN user_id INT)
BEGIN
DECLARE done INT DEFAULT FALSE;
DECLARE definition_label CHAR(255);
DECLARE label_cursor CURSOR FOR SELECT DISTINCT label FROM example_db.user_preferences;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
@chappy84
chappy84 / HTML5.localStorage.js
Last active Dec 31, 2017
HTML5 Storage without the restrictions on storing objects
View HTML5.localStorage.js
if (typeof HTML5 == 'undefined') {
var HTML5 = {};
}
/**
* Wrapper class to deal with easily storing values in local storage
* without having to constantly use JSON.parse and JSON.stringify everywhere
* you want to save an object.
*
* @param {String} index the base index to use in the localStorage global object
* @author Tom Chapman
@chappy84
chappy84 / mongodb-install.sh
Last active Jan 23, 2018
Install MongoDB from source on Fedora/RedHat based Linux with SystemD
View mongodb-install.sh
#!/bin/sh
# MongoDB Version
MONGODB_VER='2.2.2'
# Get all the dependencies up to date
yum -y update
yum -y install scons gcc-c++ glibc-devel
# Get the source
@chappy84
chappy84 / linode-centos-6-or-newer-native-kernel.sh
Last active Feb 13, 2018
Install the native kernel on a CentOS 6 and Newer Linode
View linode-centos-6-or-newer-native-kernel.sh
### Starting from a fresh CentOS 6 or newer Linode
### Enable the native kernel to boot from pvgrub
### It will autoconfigure itself with each yum update.
### This is adapted from a previous script for CentOS 5.5 found here:
### http://www.linode.com/docs/assets/542-centos5-native-kernel-selinux-enforcing.sh
### Provided via the linode wiki
### https://www.linode.com/docs/tools-reference/custom-kernels-distros/run-a-distributionsupplied-kernel-with-pvgrub#centos-5
### Provided without warranty, although since it should only be run
### on first box build if your box gets broken simply rebuild it
You can’t perform that action at this time.