Skip to content

Instantly share code, notes, and snippets.


SeanJA SeanJA

View GitHub Profile
SeanJA / form.class.php
Created Mar 26, 2010
starting of a form class
View form.class.php
//I hate typing in htmlspecialchars() all the time
function h($var) {
return htmlspecialchars($var);
//cake's inflector class
class form {
* Contains the form as a string
SeanJA / datetime_52.class.php
Created Mar 30, 2010
A fix for missing functionality in php 5.2's DateTime class
View datetime_52.class.php
* Provides backwards support for php 5.2's lack of setTimestamp and getTimestamp
class DateTime_52 extends DateTime{
* Set the time of the datetime object by a unix timestamp
* @param int $unixtimestamp
* @return DateTime_52
View get_class.php
* @property-read string $class_name
abstract class rootClass{
* Contains the data for this class
* @var array
protected $data = array();
SeanJA / poorman_mvc.php
Created Apr 6, 2010
a bad way to do mvc...
View poorman_mvc.php
$location = isset($_GET['location'])? $_GET['location'] : 'home';
/// include the correct page if it is in our list, or open the home page
case 'blog':
case 'comments':
case 'new_comment':
case 'new_post':
SeanJA / dummy_classes.php
Created May 21, 2010
A factory that remembers
View dummy_classes.php
* @property int $id
* @property string $class_name
abstract class root {
* the identifier of this object
* @var int
View selectgender2.php
* Create a select box
* @param string $name the name of the select box
* @param array $options the options, associative array array('val_1'=>'opt_1' ... )
* @param string $selected the option that is selected
* @param array $attributes associative array of attributes for the select box array('attr_1'=>'val_1', 'attr_2'=>'val_2')
function html_select($name, array $options, $selected=null, array $attributes = array()) {
View pagination_view.php
//this would come from a database count function
$totalPages = 200;
//presumably this comes from the get variable
$currentPage = 20;
//if the current page > total pages, just set it to the number of pages,
//someone is messing with the url
if ($currentPage > $totalPages) {
$currentPage = $totalPages;
SeanJA / index.php
Created Jun 10, 2010 — forked from gavinblair/index.php
mobile browser detection
View index.php
$mobiles = array(
'iphone','ipod','android','blackberry',//and so on
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if($match = preg_match('/('.implode('|',$mobiles).')/', $agent)){
echo 'mobile';
//include mobile stuff here
} else {
View nonscary.js
* Try and split a selector into its parts (. # are really the only ones supported)
function splitSelector(selector){
var selectors = [];
selector = selector.split(/(\W)/);
selectors.push(selector.shift() +''+ selector.shift());
} else if(selector[0].match(/\w/)) {
View htmlpurifier.php
//add rel="nofollow" and target="_blank" to links with htmlpurifier 4.1.1
require_once '../../library/';
class HTMLPurifier_AttrTransform_AValidator extends HTMLPurifier_AttrTransform
var $name = 'Link validation';
function transform($attr, $config, $context) {
$attr['target'] = '_blank';