Skip to content

Instantly share code, notes, and snippets.

View treffynnon's full-sized avatar
🧟

Simon Holywell treffynnon

🧟
View GitHub Profile
@treffynnon
treffynnon / gist:1031709
Created June 17, 2011 16:04
Disable weekends on a jQuery Tools DateInput
var dateinput = $('input[type="date"]').dateinput({
"onShow": function(event) {
var calendar = this.getCalendar();
var conf = this.getConf();
var classes = conf.css.off + ' ' + conf.css.disabled;
function disableWeekends() {
var weeks = calendar.find('.calweek');
weeks.find('a:first, a:last').addClass(classes);
}
calendar.find('#calprev, #calnext').click(disableWeekends);
# File: ~/.bash_profile
# source ~/.profile, if available
if [[ -r ~/.profile ]]; then
. ~/.profile
fi
# start agent and set environment variables, if needed
agent_started=0
if ! env | grep -q SSH_AGENT_PID >/dev/null; then
@treffynnon
treffynnon / .bash_logout
Created April 26, 2011 09:17 — forked from bobthecow/.gitconfig
dot files
# stuff to add at end of ~/.bash_logout
if ((agent_started)); then
echo "Killing ssh agent"
ssh-agent -k
fi
@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 / LegacyIncludes.php
Created November 26, 2010 21:58
Legacy class code loader
<?php
$dir = 'classes/';
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..' && !is_dir($dir.$file)){
require_once($dir.$file);
}
}
closedir($dh);
@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 / gist:608936
Created October 3, 2010 21:06
An Excellent Development Server for a Team of Developers
# This file is /etc/apache2/httpd.conf
# This file is automatically included by Ubuntu in /etc/apache2/apache2.conf
Include /etc/apache2/dev-server.conf
@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 / firefox-auto-complete-off.js
Created August 9, 2010 18:55
Firefox with Radio Inputs and it's Annoying Autocomplete
if($.browser.mozilla) {
$("form").attr("autocomplete", "off");
}
@treffynnon
treffynnon / drop-cap-regex.php
Created July 9, 2010 17:31
Regex for adding a drop cap span into article text
<?php
$article['full_text'] = preg_replace('/^([\<\sa-z\d\/\>]*)(([a-z\&\;]+)|([\"\'\w]))/', '$1<span class="drop-cap">$2</span>', $article['full_text']);