Skip to content

Instantly share code, notes, and snippets.

View jbrooksuk's full-sized avatar
🧑‍🚀

James Brooks jbrooksuk

🧑‍🚀
View GitHub Profile
@jbrooksuk
jbrooksuk / jQuery Create Plugin
Created April 11, 2011 12:28
Creates DOM elements taking an element and a set of attribute properties
(function($) {
$.fn.create = function(el, attr) {
return jQuery(document.createElement(el)).attr(attr).prependTo(this);
}
})(jQuery);
@jbrooksuk
jbrooksuk / Raw HTML from element
Created April 12, 2011 08:05
Returns the raw HTML code for a supplied element.
(function($) {
$.fn.nodeHTML = function() {
return jQuery('<div>').append(jQuery(this).clone()).remove().contents().html();
};
})(jQuery);
@jbrooksuk
jbrooksuk / Sublime Text 2 PHP Build
Created April 12, 2011 08:34
Build file for PHP under Sublime Text Alpha 2
{
"cmd": ["php", "-l", "$file"],
"selector": "source.php",
"file_regex": "^Parse error: .* in (.*?) on line ([0-9]*)"
}
@jbrooksuk
jbrooksuk / gist:1004154
Created June 2, 2011 09:16
Table rows/cols selection
<!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 June 3, 2011 12:53
jQuery Plugin to reverse $.each
jQuery.fn.reverse = [].reverse;
@jbrooksuk
jbrooksuk / gist:1327855
Created October 31, 2011 16:12
PHP Switch in_array
<?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':
@jbrooksuk
jbrooksuk / gist:1336986
Created November 3, 2011 16:37
raise_array
<?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 March 13, 2012 15:16
Calculates a percentage off of a price, then rounds to the next 9.
<?php
function calcPPrice($iPrice, $iDPrice = 1) {
$iDiscounted = round($iPrice - ($iPrice / 100 * $iDPrice));
return $iDiscounted - (10 - (9 - ($iDiscounted % 10)));
}
?>
@jbrooksuk
jbrooksuk / gist:2204090
Created March 26, 2012 09:14
PHP .properties class
<?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 August 14, 2012 09:53
Bugify External Hook URL - Pushover
<?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.