Skip to content

Instantly share code, notes, and snippets.

@chrisdiana
chrisdiana / gist:ff9f6f9e702b5e989a57
Created Sep 15, 2014
Sort array by child array key
View gist:ff9f6f9e702b5e989a57
<?php
function cust_sort($a,$b) {
return strtolower($a['name']) > strtolower($b['name']);
}
usort($dealers, 'cust_sort');
?>
@chrisdiana
chrisdiana / gist:7e304600a59ee95ef077
Created Sep 15, 2014
Edit default select option
View gist:7e304600a59ee95ef077
window.onload = function () {
document.getElementsByClassName('select')[0].options[0].text='Services';
}
View gist:b2c604c99409d0cd2a0b
<?php
// Grab XML
$xml_file = "rsform.xml";
// Load xml data.
$xml = file_get_contents($xml_file);
// Strip whitespace between xml tags
$xml = preg_replace('~\s*(<([^>]*)>[^<]*</\2>|<[^>]*>)\s*~','$1',$xml);
// Convert CDATA into xml nodes.
$xml = simplexml_load_string($xml,'SimpleXMLElement', LIBXML_NOCDATA);
// Make variables
@chrisdiana
chrisdiana / gist:7365a974255816fd75e8
Created Sep 15, 2014
Add admin menu if user is logged in in Joomla
View gist:7365a974255816fd75e8
<?php /* Admin menu if user is logged in */ ?>
<style type="text/css">#admin-menu {display:none !important;}</style>
<?php
$usr = JFactory::getUser();
if(0!=$usr->get('id')) : ?>
<style type="text/css">#admin-menu {display:block !important;}</style>
<?php endif; ?>
@chrisdiana
chrisdiana / gist:00cc833e2885908410bb
Created Sep 15, 2014
Use curl to get json data from URL
View gist:00cc833e2885908410bb
<?php
$url = "http://somesite.com/jsondata";
echo "<pre>";
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
@chrisdiana
chrisdiana / gist:6d975c4c1500a77aa0fb
Created Sep 15, 2014
Get the address of a location using Google Maps API
View gist:6d975c4c1500a77aa0fb
<?php
$eventAddress = $event->address;
// Get the zip code at the end of the address
$zipcode = substr($eventAddress, -5);
// Use google map API to get the state code
$mapurl = "http://maps.googleapis.com/maps/api/geocode/xml?address='.$zipcode.'@&sensor=true";
// Load XML
$xml = simplexml_load_file($mapurl);
// Get Statecode from XML
$statecode = $xml->result->address_component[3]->short_name;
@chrisdiana
chrisdiana / gist:f94ec118cbbca52ccda4
Created Sep 15, 2014
Function to Get First Paragraph in Page
View gist:f94ec118cbbca52ccda4
<?php
function getFirstPara($string){
$string = substr($string,0, strpos($string, "</p>")+4);
return $string;
}
echo getFirstPara($texthere);
?>
View gist:57434d983717e0cc8207
<div class="hidden">
<div class="wrapper">
<header>
<h1>Improved full width browser bars</h1>
</header>
<p>This white area is a simple 960 wrapper</p>
</div>
</div>
<style type="text/css">
@chrisdiana
chrisdiana / gist:e7bb7187a9b526d84355
Created Sep 15, 2014
Alternate colors with pure CSS
View gist:e7bb7187a9b526d84355
td:nth-of-type(3n+0){
border-top: 8px solid #7DBA28;
}
td:nth-of-type(3n+1){
border-top: 8px solid #152239;
}
td:nth-of-type(3n+2){
border-top: 8px solid #3D988A;
}
View gist:dee64ebc51f1825b70a0
.crop-height {
/* max-width: 1200px; /* img src width (if known) */
max-height: 320px;
overflow: hidden;
}
img.scale {
/* corrects inline gap in enclosing div */
display: block;
max-width: 100%;