Skip to content

Instantly share code, notes, and snippets.

@davemackintosh
davemackintosh / getDistanceBetweenLatLongs.js
Last active December 17, 2015 02:59
Get the distance between a starting and ending lat/long in JavaScript.
;function getDistanceBetweenLatLongs (start, end) {
// Starting lat, long
var lat1 = start.lat.toRad();
var lng1 = start.lng.toRad();
// Destination lat, long
var lat2 = end.lat.toRad();
var lng2 = end.lng.toRad();
// Earths radius in km
@davemackintosh
davemackintosh / gist:5238776
Last active December 15, 2015 09:29
JS function to lighten or darken a HEX colour.
/**
* Util function for lightening the colour with a %
* @param - string - colour with leading #
* @param - number - percentage to lighten by
*/
function lighten (c,p) {
var n = parseInt(c.slice(1),16)
, a = Math.round(2.55 * p)
// Bitshift 16 bits to the left
, r = (n >> 16) + a
@davemackintosh
davemackintosh / Array.prototype.recursiveArrayIterator.js
Created December 10, 2012 11:06
JavaScript recursive array iterator
/**
* Prototype for recursively iterating over an array of
* arrays.
* @author Dave Mackintosh
* @param callback function
*/
Array.prototype.recursiveArrayIterator = function (cb) {
this.forEach(function (obj, inx) {
// If it's an array we want to fire another iterator
// with our parent array as a separate argument
/**
* @param slides ~ Array (ARRAY) of image locations
* @param duration ~ Number - in milliseconds how long to run for
* @param element ~ jQuery object - The <img> tag to change the src of.
* @returns void
*
* @example
* <img src="#" id="sequence" data-loop="true" data-autoplay="true" />
* <script>var vid = new PNGSequence(tiffanyCrystal, 4, $('#sequence'));</script>
*/
@davemackintosh
davemackintosh / gist:2623103
Created May 6, 2012 16:06
Popular Products Module
<?php
//Popular products function
function popular_products ($atts) {
//Expose the Db to the function
global $wpdb;
//Get the results
$pp = $wpdb->get_results("SELECT `prodid`, SUM(quantity)
FROM `{$wpdb->prefix}wpsc_cart_contents`
@davemackintosh
davemackintosh / gist:2585824
Created May 3, 2012 13:58
Sample for my blog
<div id="MyArticles">
<section></section>
<section></section>
</div>
<style>
section {
width:80%;
float:left;
}
article {
width:20%;
float:right;
}
</style>