Skip to content

Instantly share code, notes, and snippets.

View pkdavies's full-sized avatar

Peter Davies pkdavies

View GitHub Profile
@pkdavies
pkdavies / gist:1022608
Created June 13, 2011 11:07
Making pre Zend Framework 1.0 applications work
/* -- set a non-existent error handler + view renderer -- */
$controller->returnResponse(true);
$controller->setParam('useDefaultControllerAlways', true);
$controller->setParam('noErrorHandler', true);
$controller->setParam('noViewRenderer', true);
$response = $controller->dispatch();
@pkdavies
pkdavies / optimise.pl
Created June 21, 2011 10:28
Optimise MySQL databases
#!/usr/bin/perl
use DBI;
$dbi_host="localhost";
# all databases
@dbi_u=("admin_user");
@dbi_p=("qwerty");
#set the max count value
@pkdavies
pkdavies / combobox-backbase.php
Created June 21, 2011 10:58
Backbase Combobox + PHP
public function combobox($name, $values_array, $default=null, $size=300, $required=false){
$req_bxml = ($required)? " b:required=\"true\"" : "";
$bxml = '<b:combobox b:width="'. $size .'px" b:name="'. $name .'" b:text="'. $default .'"'. $req_bxml .'>';
foreach ($values_array as $value) {
$bxml .= '<b:combo-option b:value="'. $value['value'] .'">'. $value['name'] .'</b:combo-option>';
}
$bxml .= '</b:combobox>';
return $bxml;
}
@pkdavies
pkdavies / gist:1037627
Created June 21, 2011 11:02
MySQL timestamp format to human readable
function mysql_timestamp_to_human($dt){
$yr=strval(substr($dt,0,4));
$mo=strval(substr($dt,4,2));
$da=strval(substr($dt,6,2));
$hr=strval(substr($dt,8,2));
$mi=strval(substr($dt,10,2));
//$se=strval(substr($dt,12,2));
return date("m/d/Y H:i", mktime ($hr,$mi,0,$mo,$da,$yr))." GMT";
}
@pkdavies
pkdavies / gist:1037649
Last active September 26, 2015 04:17
MS Word "save as HTML" and HTML Purifier
<?php
if ($_POST['q']){
$dirty_html = $_POST['q'];
if (!$dirty_html) {
echo ('You must write some HTML!');
} else {
$config = HTMLPurifier_Config::createDefault();
$config->set('Core', 'Encoding', 'ISO-8859-1');
$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional');
$config->set('HTML', 'TidyLevel', 'heavy');
@pkdavies
pkdavies / gist:1037701
Created June 21, 2011 11:55
Emergency Joomla password reset
<?php
$mysql_host = "localhost";
$mysql_user = "";
$mysql_password = "";
$mysql_db = "";
$user = "admin";
$pass = "qwerty";
$pass_enc = md5($pass);
@pkdavies
pkdavies / fix.sh
Created June 21, 2011 13:01
Update filenames removing ampersand
ls -1 | while read file
do
target=$(echo $file | sed -e "s/\&/_/")
mv "$file" "$target"
done
@pkdavies
pkdavies / fixdb.php
Created June 21, 2011 13:17
Find and replace in MySQL - using PHP
<?php
// Find and replace facility for complete MySQL database
//
// Originally written by Mark Jackson @ MJDIGITAL
// Can be used by anyone - but give me a nod if you do!
// http://www.mjdigital.co.uk/blog
// http://www.mjdigital.co.uk/blog/search-and-replace-text-in-whole-mysql-database/
//
// PKDAVIES:
// Changed REGEX to LIKE
@pkdavies
pkdavies / gist:1037940
Created June 21, 2011 14:13
Combine multiple text files
#!/bin/bash
for file in `ls ./*.txt`
do
cat $file >> all.files
done
@pkdavies
pkdavies / gist:1071669
Created July 8, 2011 11:51
fgetcsv to mysql insert statements
<pre>
<?php
$row = 0;
if (($handle = fopen("data.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$model_id = $data[1];
for ($c=2; $c < $num; $c++) {
if (!empty($data[$c])){