Skip to content

Instantly share code, notes, and snippets.

@jkjustjoshing
jkjustjoshing / sleep.js
Last active July 9, 2021 23:05
Scrape connect.garmin.com sleep data
(async () => {
const dateStr = (dateObj) => `${dateObj.getUTCFullYear()}-${String(dateObj.getUTCMonth() + 1).padStart(2, '0')}-${String(dateObj.getUTCDate()).padStart(2, '0')}`
const getData = async (dateObj) => {
const date = dateStr(dateObj)
const username = ''
const resp = await fetch(`https://connect.garmin.com/modern/proxy/wellness-service/wellness/dailySleepData/${username}?date=${date}&nonSleepBufferMinutes=60`, {
"headers": {
@jkjustjoshing
jkjustjoshing / machine.js
Last active April 7, 2020 00:18
Generated by XState Viz: https://xstate.js.org/viz
const calculationMachine = Machine(
{
id: 'calculator',
initial: 'init',
context: {
number1: '',
operand: null,
number2: '',
result: null,

Keybase proof

I hereby claim:

  • I am jkjustjoshing on github.
  • I am jkjustjoshing (https://keybase.io/jkjustjoshing) on keybase.
  • I have a public key ASAutzKPY2wB2OXvsSYnqsYBqR26-vbUQOYGHMl_tKoDlwo

To claim this, I am signing this object:

@jkjustjoshing
jkjustjoshing / machine.js
Last active September 4, 2019 20:39
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jkjustjoshing
jkjustjoshing / hal-higdon-export.js
Last active July 23, 2018 20:02
This scrapes the HTML on Hal Higdon's training pages, with a race date, and exports a .ics file to import the workouts into Google Calendar, iCal, etc.
(function () {
function hashCode (string){
var hash = 0;
if (string.length == 0) return hash;
for (i = 0; i < string.length; i++) {
char = string.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
@jkjustjoshing
jkjustjoshing / gist:66232b2d8dcdd2bc181d
Last active April 6, 2017 05:53
Garmin export bookmarklet
(function() {
var jQuery = document.querySelector('iframe').contentWindow.jQuery;
jQuery('.activityName').each(function(){
var $this = jQuery(this);
$this.css({
overflow:'auto',
width:'200px'
});
@jkjustjoshing
jkjustjoshing / $inject.user.js
Last active December 6, 2021 16:32
Angular $inject userscript.
// ==UserScript==
// @name AngularJS Injector
// @namespace http://joshkra.me/
// @version 0.1
// @description Binds $inject method to window
// @author jkjustjoshing
// @match *://*/*
// ==/UserScript==
// This userscript creates an $inject() method on the window object that can be used to
@jkjustjoshing
jkjustjoshing / promise.any-slim.js
Last active July 19, 2017 10:11
Promise.any() – A Missing Use Case
Promise.any = function(arrayOfPromises) {
// For each promise that resolves or rejects,
// make them all resolve.
// Record which ones did resolve or reject
var resolvingPromises = arrayOfPromises.map(function(promise) {
return promise.then(function(result) {
return {
resolve: true,
result: result
};