Skip to content

Instantly share code, notes, and snippets.

View Petah's full-sized avatar

David Neilsen Petah

  • Hamilton, New Zealand
View GitHub Profile
@Petah
Petah / CSV.php
Created February 10, 2012 04:42
PHP CSV class
<?php
/**
* XMod\Common\CSV
* @link http://www.csvreader.com/csv_format.php
* @todo Might need option to replace characters like " with '
* @todo Needs option to escape non printable characters
* Escape codes: \### and \o### Octal, \x## Hex, \d### Decimal, and \u#### Unicode
* @author David Neilsen <david@panmedia.co.nz>
*/
namespace XMod\Format;
@Petah
Petah / Args.php
Created February 10, 2012 04:44
PHP CSV Class
<?php
/**
* XMod\Common\Args
*
* @file
* @author David Neilsen <david@panmedia.co.nz>
*/
namespace XMod\Common;
use IteratorAggregate;
use RecursiveIteratorIterator;
@Petah
Petah / XModHTMLTag.php
Created September 6, 2012 01:07
Abstract Tags
<?php
/**
* XMod\HTML\Tag
*
* @author David Neilsen <david@panmedia.co.nz>
*/
namespace XMod\HTML;
use XMod\Common\Args;
/**
@Petah
Petah / gist:3777649
Created September 24, 2012 19:01
Counter
class Counter {
private $counter = 0;
public function getCounter()
{
return $this->counter;
}
public function incrementCounter()
{
@Petah
Petah / Poller.php
Created November 7, 2012 22:25
Example background thread script
// Get the current working directory
$current = getcwd();
// An array of real paths of directories already run
$done = array();
// Background processes
$processes = array();
foreach ($directories as $directory) {
@Petah
Petah / current.html
Created November 15, 2012 22:50
Raptor Example
<script type="text/javascript">
raptor(function($) {
$('.editable').editor({
urlPrefix: '/'
});
});
</script> <script type="text/javascript">
jQuery(function($) {
$('.editable').editor({
urlPrefix: '../',
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?parameter=$1 [NC]
<div class="raptor-editable" data-id="main-content">
<p>
Raptor may be integrated into a site many ways.
This article aims to cover the simplest integration possible.
</p>
</div>
<script>
$(function() {
$('.raptor-editable').raptor({
plugins: {
@Petah
Petah / mail.php
Created July 24, 2013 21:37
Simple PHP email test script.
<?php
// Disclaimer: this script is for test purposes only, it is not intended to be secure.
ini_set('display_errors', 1);
error_reporting(E_ALL);
if (isset($_POST['to']) &&
isset($_POST['from']) &&
isset($_POST['subject']) &&
isset($_POST['message'])) {
$headers = 'From: ' . $_POST['from'] . PHP_EOL
. 'Reply-To: ' . $_POST['from'] . PHP_EOL
@Petah
Petah / backup-mysql.php
Created July 25, 2013 02:23
MySQL Backup Script
<?php
function backup($database, $path) {
if (!file_exists($path)) {
mkdir($path);
}
if (!is_dir($path)) {
echo 'Could not create directory: ' . $path . PHP_EOL;
return;
}
file_put_contents("$path/$database.timestamp", date('Y-m-d H:i:s'));