Skip to content

Instantly share code, notes, and snippets.

@randycasburn
randycasburn / yearly, weekly, monthly data for chartsjs
Created April 11, 2022 20:16
Provides one way of creating a Map for use in Chartsjs
@RequestMapping(path = "/test", method = RequestMethod.GET)
public String showTest(@RequestParam(required = false) String timeframe, ModelMap model) {
Map<String, Integer> data = new LinkedHashMap<>();
timeframe = timeframe == null ? "Yearly" : timeframe.toLowerCase();
if (timeframe.equals("yearly")) {
// For this year
LocalDate startDate = LocalDate.ofYearDay(LocalDate.now().getYear(), 1);
for (int i = 0; i < 12; i++) {
String monthOfYear = StringUtils.capitalize(startDate.getMonth().toString());
@randycasburn
randycasburn / Main.java
Created May 27, 2021 03:29
SimpleEnumCalculator
package com.company;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BinaryOperator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {

Resource Loading and Timing

As usual, someone had the same idea and has provided a pre-coded solution. I discovered these resources in an attempt to help you with this very complicated task. You can use the code as written or place it into a bookmarklet.

I found a detailed article that describes how to use both the [Navigation Timing API][1] & the [Resource Timing API][2] The article I came across is titled (and found at):

[Assessing Loading Performance in Real Life with Navigation and Resource Timing][3]

The two prebuilt solutions provided by that article take completely different approaches to visualizing the data you seek.

/*
* Uses Resource Timing API to build a page load waterfall
*
* Only currently works in IE10, and Chromium nightly builds, has a few issues still to be fixed,
* contributions welcomed!
*
* Feel free to do what you want with it, @andydavies
*
* To use, create a bookmark with the script below in, load a page, click the bookmark
*
function addTogether(...args) {
if (args.length > 2 || args.some(p => p.constructor !== Number)) return;
return args.length === 2 ? args[0] + args[1] : (n) => addTogether(args[0], n);
}
console.log(addTogether(2, 3));
console.log(addTogether(2)(3));
if (exerciseName !== obj.exercise) {
let obj = {
exercise: 'remove',
exerciseDescription: '',
AlternativeExercise: '',
};
continue;
}
/* then after while loop */
var
/* Save the canvas' context. */
ctx = document.getElementById("myCanvas").getContext("2d"),
/* The starting opacity. */
opacity = 0,
/* The duration of the animation in milliseconds. */
duration = 500,
obj1 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":true } };
]obj2 = { "val1":"test", "stream":{ "iscommisonAccount":true, "istradeAccount":true } };
obj3 = { "val1":"test", "stream":{ "iscommisonAccount":true, "istradeAccount":true } };
obj4 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":true } };
obj5 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":false } };
obj6 = { "val1":"test", "stream":{ "iscommisonAccount":false, "istradeAccount":false } };
@randycasburn
randycasburn / AsyncGenerator.js
Created November 30, 2020 03:52
Use of an Async Generator function to retrieve data over time and update the display with a subset of records at a time
// DOM element to recieve dispatched event and data
const showResults = document.getElementById('showResults');
// CustomEvent listener
showResults.addEventListener('gotData', doDOM);
// Random _count_ to show (between 1-5)
const numberToShow = Math.ceil(Math.random() * (5 - 1) + 1);
// iterator Object (has .next() method)
const iterator = nextSet(numberToShow);
/**
// Create a DOM document
const htmlString = "<pre>Some document span that <span>may</span> have arbitrary <b>span</b> all over span it</pre>";
const parser = new DOMParser();
const doc = parser.parseFromString(htmlString, "text/html");
// Here is the JavaScript work around...
const stringToSearch = 'span';
const domWalker = doc.createTreeWalker(doc.documentElement, NodeFilter.SHOW_TEXT);
let node;
let newHTML = '';