Skip to content

Instantly share code, notes, and snippets.

View bretdavidson's full-sized avatar

Bret Davidson bretdavidson

  • North Carolina State University Libraries
View GitHub Profile
// parseURL function from James padolsey
// http://james.padolsey.com/javascript/parsing-urls-with-the-dom/
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
function parseUri (str) {
var o = parseUri.options,
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
uri = {},
i = 14;
// Taken from: http://stackoverflow.com/a/9349999
// <img data-other-src="big-zebra.jpg" src="small-zebra.jpg">
// <img data-other-src="big-elephant.jpg" src="small-elephant.jpg">
// <img data-other-src="big-bear.jpg" src="small-bear.jpg">
$(function () {
$('img').on('mouseenter mouseleave', function () {
$(this).attr({
src: $(this).attr('data-other-src'),
// Taken from: http://stackoverflow.com/a/476681
(function() {
var arrayOfImages = ["one.jpg", "two.jpg", "three.jpg"];
function preload(arrayOfImages) {
$(arrayOfImages).each(function () {
$('<img/>')[0].src = this;
});
}
var Distance = {
rad: function (x) {
return x * Math.PI / 180;
},
haversine: function (p1, p2) {
var R = 637100000,
dLat = this.rad(p2.latitude - p1.latitude),
dLong = this.rad(p2.longitude - p1.longitude),
<?php
// Takes two dates formatted as YYYY-MM-DD and creates an
// inclusive array of the dates between the from and to dates.
// Taken from: http://stackoverflow.com/a/4312491
function createDateRangeArray($sDate, $eDate)
{
$range = array();

DESCRIPTION

@bretdavidson
bretdavidson / difference.js
Last active June 12, 2017 13:35
Possible Interview Questions
// Remove elements of second array from the first array
// Ex. 1 JavaScript Filter (no IE 8 support)
var arr1 = ['A', 'B', 'C', 'D', 'E', 'F'],
arr2 = ['C', 'E', 'F'],
filteredArray;
filteredArray = arr1.filter(function(e, i) {
return !(arr2.indexOf(e) > -1);
});
Handlebars.registerHelper('quotify', function (string) {
var string = string.replace(/[\u2018\u2019]/g, "'").replace(/[\u201C\u201D]/g, '"');
return string;
});