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 / 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 / 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: '../',
<?php
$errors = [
'name' => null,
'email' => null,
'message' => null,
];
if (!empty($_POST)) {
if (!isset($_POST['name'])) {
$errors['name'] = 'Your name is required';
} elseif (strlen($_POST['name']) > 100) {
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 / tag.php
Last active December 16, 2015 02:54
<?php
class Tag {
private $name;
private $attributes = [];
private $content = [];
public function __construct($name) {
$this->name = $name;
}
@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'));
@Petah
Petah / index.php
Last active January 31, 2016 15:57
2-cms
<?php
$view = preg_replace('/[^a-z]/', '', $_SERVER['REQUEST_URI']) ?: 'index';
require __DIR__ . '/layout.php';