Skip to content

Instantly share code, notes, and snippets.

View jnritchie's full-sized avatar

Justin Ritchie jnritchie

  • Caribbean
View GitHub Profile
@jnritchie
jnritchie / distance-calc.js
Created October 17, 2022 18:34
Calculate distance between to points using Haversine formula
var rad = function(x) {
return x * Math.PI / 180;
};
var getDistance = function(p1, p2) {
var R = 6378137; // Earth’s mean radius in meter
var dLat = rad(p2.lat() - p1.lat());
var dLong = rad(p2.lng() - p1.lng());
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) *
@jnritchie
jnritchie / contextmenu.html
Created October 5, 2022 02:26
Block Right Click on IMG element - vanilla JS
<html>
<head>
<title>Context Menu Block</title>
<script>
document.addEventListener('contextmenu',(e)=> {
if(e.target.nodeName === 'IMG'){
e.preventDefault();
}
})
</script>
@jnritchie
jnritchie / agent-search.js
Created January 26, 2020 16:51
VueJS Agent Lookup and GeoCode
var gmstyles = [
{
"featureType": "road",
"elementType": "geometry",
"stylers": [
{
"lightness": 100
},
{
"visibility": "simplified"
@jnritchie
jnritchie / featuredMappoints.js
Last active July 1, 2019 17:32
Ajax rendered map points with ajax data in info window.
function initMap(){
var mia = { lat:25.778850, lng:-80.207486 };
var mapCanvas = document.getElementById('map');
var mapOptions = {
center: mia,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true,
styles:
@jnritchie
jnritchie / index.html
Created April 17, 2019 03:07 — forked from gaearon/index.html
Add React in One Minute
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Add React in One Minute</title>
</head>
<body>
<h2>Add React in One Minute</h2>
<p>This page demonstrates using React with no build tooling.</p>
@jnritchie
jnritchie / csv-to-json.php
Created March 24, 2019 15:39 — forked from robflaherty/csv-to-json.php
Convert CSV to JSON
<?php
/*
* Converts CSV to JSON
* Example uses Google Spreadsheet CSV feed
* csvToArray function I think I found on php.net
*/
header('Content-type: application/json');
// Set your CSV feed
@jnritchie
jnritchie / yvideoRandomizer.js
Created March 14, 2019 15:38
Video Randomizer - untested
var vids = ["https://www.youtube.com/watch?v=fdJc1_IBKJA",
"https://www.youtube.com/watch?v=xaDZvw9ot3E",
"https://www.youtube.com/watch?v=3WWlhPmqXQI"]; // create your list of youtube videos
var currVid = vids[Math.floor(Math.random()*(vids.length-1))]; // this will grab a random video from the array.
var opts = { // keep all the options in an object
videoURL: currVid, // set the video to display
containment:'.video-section',
quality:'large',
@jnritchie
jnritchie / randomnumber.js
Created March 14, 2019 15:36
Random Number from set
// Generate Random Number in
var minNumber = 1;
var maxNumber = 4;
var randomNumber = randomNumberFromRange(minNumber, maxNumber);
function randomNumberFromRange(min,max)
{
return Math.floor(Math.random()*(max-min+1)+min);