Skip to content

Instantly share code, notes, and snippets.

View treffynnon's full-sized avatar
🧟

Simon Holywell treffynnon

🧟
View GitHub Profile
@treffynnon
treffynnon / LazyLoadingProxy.php
Created December 1, 2010 22:03
A simple example of using a Lazy Loading Proxy object in PHP. It is useful when attempting to work with legacy code for logging and memory savings when working with global objects..
<?php
/**
* @author Simon Holywell <treffynnon@php.net>
*/
class LazyLoadingProxy {
/**
* Where the instance of the actual class is stored.
* @var $instance object
*/
private $instance = null;
@treffynnon
treffynnon / Config.php
Created September 3, 2010 09:20
A PHP class to access a PHP array via dot notation
<?php
namespace Treffynnon;
/**
* A PHP class to access a PHP array via dot notation
* (Agavi http://www.agavi.org was the inspiration).
*
* This was hacked in to an existing codebase hence the
* global config array variable.
@treffynnon
treffynnon / convert.php
Last active December 21, 2019 12:28
Pelican to Hugo reStructuredText post converter (Python static site generator to Go static site generator)
<?php
/**
* Requires pandoc to be installed and in your path
*
* It will look for .rst files in __DIR__/content/* where it will expect to find
* category folders. Inside these category folders your posts should be available.
*
* So
*
@treffynnon
treffynnon / exec-tasks-php.php
Created February 4, 2010 15:19
PHP: Scheduled tasks executed from PHP
<?php
exec('schtasks /Delete /TN taskname /F');
exec('schtasks /Create /RU username /RP password /SC MINUTE /MO 2 /TN taskname /TR “C:\Program Files\wget\wget.exe --header=TASK_KEY:my-secret-key –U my-agent http://www.webaddress.com/script.php -r');
?>
@treffynnon
treffynnon / .htaccess
Created October 6, 2010 14:20
Force URLs to lower case in a RewriteRule using PHP. Blogged at http://simonholywell.com/post/2012/11/force-lowercase-urls-rewrite-php.html
RewriteEngine on
RewriteBase /
# force url to lowercase
RewriteCond %{REQUEST_URI} [A-Z]
# ensure it is not a file on the drive first
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L]
@treffynnon
treffynnon / manifest.xml
Created April 14, 2016 01:24 — forked from hugowan/manifest.xml
auspost maninfest xml
<?xml version="1.0" encoding="UTF-8"?>
<PCMS xmlns="http://www.auspost.com.au/xml/pcms">
<SendPCMSManifest>
<header>
<TransactionDateTime>2010>01-13T16:30:00.0Z</TransactionDateTime>
<TransactionId>1</TransactionId>
<TransactionSequence>1</TransactionSequence>
<ApplicationId>MERCHANT</ApplicationId>
</header>
<body>
@treffynnon
treffynnon / ip_based_auth.php
Last active December 16, 2015 09:29
A simple PHP snippet to verify authorisation via IP address. Supports wildcard/partial IP addresses.
<?php
$allowable_ips = array(
'192.168.0.',
'8.8.8.8',
);
$is_allowed = (bool) array_filter($allowable_ips, function($value) {
return (substr($_SERVER['REMOTE_ADDR'], 0, strlen($value)) == $value);
});
<!-- In the HTML of your posts: Replace ID number with ID of your gist -->
<p class="embed_gist"><a href="http://gist.github.com/367154">http://gist.github.com/367154</a></p>
@treffynnon
treffynnon / install.sh
Created June 6, 2012 11:40 — forked from derek-watson/tumblr.rb
Tumblr to Hakyll (Markdown and reStructuredText) migration
#!/usr/bin/env bash
echo "This script will download and install the tumblr migration script"
echo "script and its dependencies on Debian systems."
echo " "
read -p "Install dependencies from apt-get? [Yn] "
if [ "$REPLY" == "" -o "$REPLY" == "y" -o "$REPLY" == "Y" ]; then
echo "Installing the dependencies..."
echo " "
sudo apt-get install libxslt-dev libxml2-dev ruby rubygems pandoc
@treffynnon
treffynnon / server.js
Created October 21, 2011 13:53
Connect to an IrisCouch database from Node.js, save a new document and retrieve it back again.
var http = require('http');
http.createServer(function (req, http_res) {
http_res.writeHead(200, {'Content-Type': 'text/plain'});
var response = '';
var cradle = require('cradle');
var connection = new(cradle.Connection)('https://subdomain.iriscouch.com', 443, {
auth: { username: 'username', password: 'password' }
});