Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrew Householder aghouseh

View GitHub Profile
@aghouseh
aghouseh / file_relink
Created Oct 10, 2012
Concrete5 Relink Files - If you accidentally and block-headedly deleted your /files/ folder, but have source images available elsewhere, use this to restore them. Crawls a given directory and matches against Concrete5 filenames to relink missing images.
View file_relink
@aghouseh
aghouseh / states and counties
Created Oct 21, 2012
PHP nested array of states and counties
View states and counties
$counties = array(
"Alabama" => array(
"Autauga County",
"Baldwin County",
"Barbour County",
"Bibb County",
"Blount County",
"Bullock County",
"Butler County",
"Calhoun County",
@aghouseh
aghouseh / get_parameters.js
Last active Dec 16, 2015
string prototype to get all query values from a URL string or alternatively search for a specific value. pieced together from various things i found on the googles.
View get_parameters.js
String.prototype.getParameters = function(key){
var urlParams,
match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')); },
query = this;
// this is hasty and fragile currently
if (query.indexOf('?') !== -1) {
View benchmark.php
<?php
$scriptStart = microtime(true);
$iterations = 5000;
$longString = str_repeat('0123456789', 102 * 5); // 10 * 102 * 5 = 5k
if (is_file(dirname(__FILE__) . '/config/site.php')) {
include(dirname(__FILE__) . '/config/site.php');
if (defined('DB_SERVER')) {
@aghouseh
aghouseh / jquery.form-clear.js
Created Jun 24, 2013
simple jQuery function to clear a form's elements. differs from a reset in that it will zero values even if they were initially checked / selected on page render.
View jquery.form-clear.js
$.fn.clear = function() {
if (this[0].tagName.toUpperCase() !== 'FORM') { return this; }
return this.find(':input').each(function() {
if (this.type === 'radio' || this.type === 'checkbox') {
this.checked = false;
} else {
$(this).val('');
}
});
}
@aghouseh
aghouseh / image.php
Last active Dec 21, 2015
concrete5 image helper extension to allow for custom rendering of img tags. the intention is to provide a way to globally update img tag rendering in the future, pending a w3c approved responsive image solution
View image.php
<?php defined('C5_EXECUTE') or die(_('Access Denied.'));
class ImageHelper extends Concrete5_Helper_Image {
/**
* Runs getThumbnail on the path, and then prints it out as an XHTML image
*/
public function outputThumbnail($obj, $maxWidth, $maxHeight, $alt = null, $return = false, $crop = false) {
$thumb = $this->getThumbnail($obj, $maxWidth, $maxHeight, $crop);
if ($return) {