Skip to content

Instantly share code, notes, and snippets.

View davemackintosh's full-sized avatar
❤️
peace

Dave Mackintosh davemackintosh

❤️
peace
View GitHub Profile
<style>
section {
width:80%;
float:left;
}
article {
width:20%;
float:right;
}
</style>
@davemackintosh
davemackintosh / gist:2585824
Created May 3, 2012 13:58
Sample for my blog
<div id="MyArticles">
<section></section>
<section></section>
</div>
@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`
/**
* @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 / 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
@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 / 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 / colourFade.js
Created June 24, 2013 09:14
Creates array of colours cross faded from start to end via the number of steps required.
function colourFade (start, end, steps) {
var steps = steps || 10;
var start = start ? start.replace('#', '') : '000000'
var end = end ? end.replace('#', '') : 'FFFFFF'
var out = {"r":[],"g":[],"b":[]};
var floor = Math.abs;
console.log(start,end,end.substr(2,4));
@davemackintosh
davemackintosh / pre-commit
Created November 13, 2013 17:55
Block master branch
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if [ $(git rev-parse --abbrev-ref HEAD) == "master" ]; then
@davemackintosh
davemackintosh / gol.lua
Last active December 30, 2015 20:29
Conway's Game of Life in Lua for the Codea iOS app
Gol = class()
function Gol:init(W, H)
-- Set the size
self.columns = W
self.rows = H
-- The varying states of cells
self._alive = 1
self._dead = 0