Skip to content

Instantly share code, notes, and snippets.

View jeremiahajohnson's full-sized avatar

Jeremiah Johnson jeremiahajohnson

View GitHub Profile
@jeremiahajohnson
jeremiahajohnson / JS Pad.js
Last active August 29, 2015 14:03
Javascript zero padding
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
pad(10, 4); // 0010
pad(9, 4); // 0009
pad(123, 4); // 0123
@jeremiahajohnson
jeremiahajohnson / GPSWeekSec.py
Created September 24, 2014 15:42
Python functions to transform GPS second to time
from decimal import Decimal
def timeconvert24(GPSweekSec):
DayOfWeek = GPSweekSec / 86400
Hour = Decimal(str(DayOfWeek))%1 * 86400 / 3600
Minute = Decimal(str(Hour))%1 * 3600 / 60
Second = Decimal(str(Minute))%1 * 60
return "%02d" % (Hour,) + ":" + "%02d" % (Minute,) + ":" + "%02d" % (Second,)
def timeconvert12(GPSweekSec):
@jeremiahajohnson
jeremiahajohnson / GPStoUTC.py
Last active April 3, 2022 02:33
Python function to take GPS week and GPS seconds and return a UTC datetime string in the format "YYYY-MM-DD HH:MM:SS"
def weeksecondstoutc(gpsweek,gpsseconds,leapseconds):
import datetime, calendar
datetimeformat = "%Y-%m-%d %H:%M:%S"
epoch = datetime.datetime.strptime("1980-01-06 00:00:00",datetimeformat)
elapsed = datetime.timedelta(days=(gpsweek*7),seconds=(gpsseconds+leapseconds))
return datetime.datetime.strftime(epoch + elapsed,datetimeformat)
weeksecondstoutc(1811,164196.732,16) ## --> '2014-09-22 21:36:52'
@jeremiahajohnson
jeremiahajohnson / javascript.js
Last active August 29, 2015 14:08
Quick starter for esri, bootstrap, jQuery, and jQuery UI
require([
"dojo/dom", "dojo/on", "dojo/query", "dojo/request","dojo/keys",
"dojo/_base/array",
"esri/map", "esri/config", "esri/urlUtils", "esri/InfoTemplate", "esri/tasks/GeometryService", "esri/toolbars/edit", "esri/graphic",
"esri/Color", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/symbols/SimpleFillSymbol",
"esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer",
"dojo/domReady!"
], function (
dom, on, dojoQuery, request, keys,
arrayUtils,
@jeremiahajohnson
jeremiahajohnson / LocalToGPS.py
Created January 6, 2015 17:13
Local time to GPS Week and GPS Seconds
def localtogps(timestring,timeformat,leapseconds,localoffset=0):
import datetime
epoch = datetime.datetime.strptime("1980-01-07 00:00:00","%Y-%m-%d %H:%M:%S")
local = datetime.datetime.strptime(timestring,timeformat)
utc = local - datetime.timedelta(hours=localoffset)
diff = utc-epoch
gpsWeek = diff.days/7
secondsThroughDay = (utc.hour * 3600) + (utc.minute * 60) + utc.second
if utc.isoweekday()== 7:
weekday = 0