Skip to content

Instantly share code, notes, and snippets.

@chappy84
chappy84 / date_iso.php
Last active December 11, 2015 01:18
Format a local time/date using an ISO Format
<?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',
#!/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 / mongodb-install.sh
Last active January 23, 2018 16:11
Install MongoDB from source on Fedora/RedHat based Linux with SystemD
#!/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 / mongod
Created December 28, 2012 10:04
Default install of MongoDB 2.2.2 installed from source running in systemd on Fedora 15
OPTIONS="--quiet -f /etc/mongod.conf"
@chappy84
chappy84 / linode-centos-6-or-newer-native-kernel.sh
Last active February 13, 2018 21:47
Install the native kernel on a CentOS 6 and Newer Linode
### 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
@chappy84
chappy84 / tidy-directory.php
Created May 20, 2012 11:31
Convert all X/HTML files in a folder to valid X/HTML using libtidy via 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 / HTML5.localStorage.js
Last active December 31, 2017 10:46
HTML5 Storage without the restrictions on storing objects
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