Skip to content

Instantly share code, notes, and snippets.

Avatar

Bret Davidson bretdavidson

  • North Carolina State University Libraries
View GitHub Profile
View parseUrl.js
// 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,
View parseUri.js
// 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;
View jqueryImageSwap.js
// 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'),
View jqueryImagePreload.js
// 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;
});
}
View haversine.js
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),
View dateRange.php
<?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();
@bretdavidson
bretdavidson / difference.js
Last active Jun 12, 2017
Possible Interview Questions
View difference.js
// 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);
});
View quotes.js
Handlebars.registerHelper('quotify', function (string) {
var string = string.replace(/[\u2018\u2019]/g, "'").replace(/[\u201C\u201D]/g, '"');
return string;
});
You can’t perform that action at this time.