Skip to content

Instantly share code, notes, and snippets.

View stonetip's full-sized avatar

Jon Nehring stonetip

View GitHub Profile
@stonetip
stonetip / tileCalc.htm
Last active January 21, 2021 03:57
Function demo to convert between lat/lon and zxy tile coordinates at a given zoom level
<html>
<head>
<title>tile calc</title>
</head>
<body>
<script>
const degToRad = Math.PI/180;
function getTileZXY(zxyStr) { // e.g. 12/773/1447
@stonetip
stonetip / fetchLib.js
Last active April 10, 2024 19:11
Demonstration of using a Promise within a function (redundant...see fetchLib.js file instead)
// Helper function to determine the appropriate content type and body formatting
function prepareData(data) {
if (data instanceof FormData) {
return { body: data };
}
if (data instanceof Object) {
return {
body: JSON.stringify(data),
headers: { "Content-type": "application/json; charset=UTF-8" }
};
@stonetip
stonetip / normalizedAngleVectorDemo.js
Created February 14, 2018 18:29
Demo using newer ecmascript features to calculate angle and direction from a set of coordinates
class Vector {
constructor(a, b) {
if (a instanceof Point && b instanceof Point) {
this.x = b.x - a.x;
this.y = b.y - a.y;
this.z = b.z - a.z;
}
else {
this.x = a || 0;
this.y = b || 0;
@stonetip
stonetip / decimalDate.js
Created November 28, 2017 18:09
Convert a decimal date to either human readable date or UNIX timestamp
function leapYear(year) {
return ((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0);
};
/**
* Converts a decimal date, e.g. January 15th 2017 would be 14 / 365 + 2017 = 2017.0384 (days start at 0)
* @param decimalDate
*/
function convertDecimalDate(decimalDate) {
const year = parseInt(decimalDate);
@stonetip
stonetip / iconizer.jsx
Last active October 22, 2017 16:37
Adobe Illustrator script to generate PNG icons for apps.
/***
Adobe Illustrator script to generate PNG icons for apps.
Current for Xcode 9 and iOS 11 as far as icon sizes go, but set icon sizes in the pixelSizes array to get what you neeed.
Will generate images for each storyboard in a document, in the format {docName}{artboardName}_{pixelSize}, e.g.
"myDocAB1_120.png"
Tested with Adobe Illustrator CC 22.0.0 and Xcode 9
***/
function saveFile(destFolder, fileName, pixelSize) {
@stonetip
stonetip / courseAngles.swift
Last active April 20, 2023 20:44
functions to use and smooth course from CLLocationManager and get north angle relative to current angle
var courseAvgX: Double = 0
var courseAvgY: Double = 0
func getVectorAvg(latestReading: Double) -> Double {
let deg2Rad = 180 / Double.pi
// convert reading to radians
var theta = latestReading / deg2Rad
// running average
public static List<List<T>> SubdivideList<T>(List<T> inputList, int divisionSize = 2)
{
var subdivisionsList = new List<List<T>>();
for (var i = 0; i < inputList.Count; i += divisionSize)
{
subdivisionsList.Add(inputList.GetRange(i, Math.Min(divisionSize, inputList.Count - i)));
}
return subdivisionsList;
@stonetip
stonetip / donutBuilderTimer.swift
Last active May 10, 2016 18:27
donut builder with timer
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
// all angles need to be converted to radians
func Degrees2Radians(degrees: Double) -> CGFloat{
return CGFloat( degrees * M_PI / 180)
}
@stonetip
stonetip / donutBuilder.swift
Last active May 6, 2016 03:52
iOS Swift playground to build a donut arc (such as for a graph)
import UIKit
// all angles need to be converted to radians
func Degrees2Radians(degrees: Double) -> CGFloat{
return CGFloat( degrees * M_PI / 180)
}
// set width and height that will be used by the view and layers
let width = 600
@stonetip
stonetip / delay.swift
Last active May 4, 2016 17:33
iOS Swift playground implementing a delayed function multiple times
import Foundation
import XCPlayground
// Allows execution to be indefinite, giving delays or callbacks time to play
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
// Delay function
func delayer(duration: Double, closure:()->()){