Skip to content

Instantly share code, notes, and snippets.

James Brooks jbrooksuk

Block or report user

Report or block jbrooksuk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jbrooksuk
jbrooksuk / jQuery Create Plugin
Created Apr 11, 2011
Creates DOM elements taking an element and a set of attribute properties
View jQuery Create Plugin
(function($) {
$.fn.create = function(el, attr) {
return jQuery(document.createElement(el)).attr(attr).prependTo(this);
}
})(jQuery);
@jbrooksuk
jbrooksuk / Raw HTML from element
Created Apr 12, 2011
Returns the raw HTML code for a supplied element.
View Raw HTML from element
(function($) {
$.fn.nodeHTML = function() {
return jQuery('<div>').append(jQuery(this).clone()).remove().contents().html();
};
})(jQuery);
@jbrooksuk
jbrooksuk / Sublime Text 2 PHP Build
Created Apr 12, 2011
Build file for PHP under Sublime Text Alpha 2
View Sublime Text 2 PHP Build
{
"cmd": ["php", "-l", "$file"],
"selector": "source.php",
"file_regex": "^Parse error: .* in (.*?) on line ([0-9]*)"
}
@jbrooksuk
jbrooksuk / gist:1004154
Created Jun 2, 2011
Table rows/cols selection
View gist:1004154
<!DOCTYPE html>
<html>
<head>
<title>jQuery RTE Dynamic Table Insertion Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style type="text/css">
.aBlock {
width: 20px;
height: 20px;
background-color: #A9EDF5;
@jbrooksuk
jbrooksuk / gist:1006285
Created Jun 3, 2011
jQuery Plugin to reverse $.each
View gist:1006285
jQuery.fn.reverse = [].reverse;
@jbrooksuk
jbrooksuk / gist:1327855
Created Oct 31, 2011
PHP Switch in_array
View gist:1327855
<?php
$curURL = trim($_SERVER['REQUEST_URI'], '/');
$arURLParts = explode('/', $_SERVER['REQUEST_URI']);
foreach($arURLParts as $urlPart) {
${$urlPart} = $urlPart;
switch ($urlPart) {
case 'hotels':
$hotelPage = (($_GET['brand'] == "excellence") ? false : true);
break;
case 'country':
View gist:1336986
<?php
function raise_array(array $arArray, $arKey) {
if(is_array($arArray[$arKey])) {
$arValues = $arArray[$arKey];
foreach($arValues as $aValue) {
$arArray[] = $aValue;
}
unset($arArray[$arKey]); // Remove key'ed value.
@jbrooksuk
jbrooksuk / calcPPrice.php
Created Mar 13, 2012
Calculates a percentage off of a price, then rounds to the next 9.
View calcPPrice.php
<?php
function calcPPrice($iPrice, $iDPrice = 1) {
$iDiscounted = round($iPrice - ($iPrice / 100 * $iDPrice));
return $iDiscounted - (10 - (9 - ($iDiscounted % 10)));
}
?>
@jbrooksuk
jbrooksuk / gist:2204090
Created Mar 26, 2012
PHP .properties class
View gist:2204090
<?php
/**
* Parses the build.properties used by Phing
* @author James <james@bluebaytravel.co.uk>
*/
class Properties {
protected static $_instance = NULL;
public static $propFile = "";
@jbrooksuk
jbrooksuk / bugfy.pushover.php
Created Aug 14, 2012
Bugify External Hook URL - Pushover
View bugfy.pushover.php
<?php
/**
* Bugify External Hook URL with Pushover.
* @author James Brooks <jbrooksuk@me.com>
*/
if(!isset($_POST['payload'])) die('Error.');
// You don't need to change this bit.
You can’t perform that action at this time.