Skip to content

Instantly share code, notes, and snippets.

View stonetip's full-sized avatar

Jon Nehring stonetip

View GitHub Profile
@stonetip
stonetip / TokenValidationHandler.cs
Last active August 29, 2015 13:55
JWT token validation class
internal class TokenValidationHandler : DelegatingHandler
{
// This function retrieves ACS token (in format of OAuth 2.0 Bearer Token type) from
// the Authorization header in the incoming HTTP request from the client.
private static bool TryRetrieveToken(HttpRequestMessage request, out string token)
{
try
{
token = null;
IEnumerable<string> authHeaders;
@stonetip
stonetip / index.html
Created February 18, 2015 17:12
zxWwOM
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div id="timerDiv" class="timerDiv">123</div>
<input id="triggerTimer" type="button" value="timer" />
@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:()->()){
@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 / 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)
}
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 / 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 / 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 / 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 / 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