Skip to content

Instantly share code, notes, and snippets.

Avatar

Bret Davidson bretdavidson

  • North Carolina State University Libraries
View GitHub Profile
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();
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 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 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 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 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 typeOf.js
// Douglas Crockford typeOf function
function typeOf(value) {
var s = typeof value;
if (s === 'object') {
if (value) {
if (value instanceof Array) {
s = 'array';
}
} else {
View dates.json
[ {
"year": "2016",
"semester": "summer 2",
"start": "2016-06-23",
"end": "2016-07-29"
},
{
"year": "2016",
"semester": "summer 1",
"start": "2016-05-16",
View startRangingBeaconsInRegion.json
{"eventType":"didRangeBeaconsInRegion","beacons":[{"major":65215,"minor":38409,"uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","rssi":-70,"proximity":"ProximityNear"},{"major":50499,"minor":1311,"uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","rssi":-73,"proximity":"ProximityNear"},{"major":28680,"minor":57614,"uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","rssi":-86,"proximity":"ProximityNear"},{"major":65523,"minor":5129,"uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","rssi":-78,"proximity":"ProximityNear"},{"major":161,"minor":7854,"uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","rssi":-74,"proximity":"ProximityNear"},{"major":16258,"minor":63095,"uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","rssi":-80,"proximity":"ProximityFar"}],"region":{"uuid":"B9407F30-F5F8-466E-AFF9-25556B57FE6D","identifier":"banana","typeName":"BeaconRegion"}}
View Friend.js
var Friend = function(name, id, friends, x, y, theta) {
this.d = 5;
this.name = name;
this.id = id;
this.theta = theta;
this.name = name;
this.pos = createVector(x, y, 0);
this.mutual = friends; // Array of ids/names
this.friends = []; // Array of friend instances
};
You can’t perform that action at this time.