Skip to content

Instantly share code, notes, and snippets.

@chappy84
chappy84 / mysql_pivot.sql
Created August 31, 2014 11:42
MySQL Pivot Stored Procedure
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 / githubStarred.php
Last active November 20, 2016 23:31
Github Starred Dates - displays when you starred repos, which seems to have disappeared from GitHub's UI :(
<?php
function errorAndDie($message) {
echo $message . PHP_EOL;
die(1);
}
$url = 'https://api.github.com/user/starred';
do {
@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 / 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 / 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 / multiple_query_deugger.php
Last active August 29, 2015 14:01
PHP PDO Mysql Multiple Query Bug Debugger. Bug Page: https://bugs.php.net/bug.php?id=61613
<?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);