Snippets Collections
 function navigationTracking() {
        const mainNav = document.querySelector(".main-navigation__main");
        if (!mainNav) return;

        const navItems = [
            {
                selector: ".main-navigation__control-link",
                type: "nav-links",
                handler: (e, el) => {
                    const btnTextRaw = el.textContent || "";
                    const btnText = btnTextRaw.replace(/\s+/g, " ").trim();
                    const isPressed =
                        el.getAttribute("aria-pressed") === "true";
                    const navState = isPressed ? "closed" : "open";

                    navigationClickTracking(btnText, null, 1, navState);
                },
            },
            {
                selector: "#main-nav-bookmarks",
                type: "nav-bookmark",
                handler: (e, el) => {
                    const btnText = el.innerText.trim();
                    navigationClickTracking(btnText, "/sruh/bookmarks", 1);
                },
            },
            {
                selector: "#main-nav-close",
                type: "nav-search",
                handler: (e, el) => {
                    const btnText = el.outerText.trim();
                    navigationClickTracking(btnText, null, 1);
                },
            },
            {
                selector: "#main-nav-quiz",
                type: "nav-quiz",
                handler: () => {
                    navigationClickTracking(
                        "Senior Road User Quiz",
                        "/sruh/quiz",
                        1,
                    );
                },
            },
        ];

        navItems.forEach((item) => {
            const elements = mainNav.querySelectorAll(item.selector);

            elements.forEach((el) => {
                if (el.dataset.navTracked) return;
                el.dataset.navTracked = "true";

                el.addEventListener("click", (e) => {
                    item.handler(e, el);
                });
            });
        });

        /*  SUB MENU LINK TRACKING */

        const subNavWrapper = document.querySelector(".main-navigation__aside");
        if (!subNavWrapper) return;

        // Use event delegation to catch all subnav link clicks
        // This works regardless of when the subnav is opened
        if (subNavWrapper.dataset.subNavTrackingSetup) return;
        subNavWrapper.dataset.subNavTrackingSetup = "true";

        subNavWrapper.addEventListener("click", (e) => {
            // Find the clicked link
            const link = e.target.closest(
                ".main-navigation__content-list li a",
            );
            if (!link) return;

            // Only track if the link is within an active menu
            const activeMenu = link.closest(".main-navigation__content.active");
            if (!activeMenu) return;

            const linkText = link.textContent.replace(/\s+/g, " ").trim();
            const linkUrl = link.getAttribute("href") || "";

            navigationClickTracking(linkText, linkUrl, 2);
        });
    }
const TEST_MODE = true; // true = preventDefault for testing, false = production
    function maybePreventDefault(e) {
        if (TEST_MODE) e.preventDefault();
    }
     // usage: maybePreventDefault(e);


//example

   function footerNavTracking() {
        const footerWrapper = document.querySelector(".footer");
        if (!footerWrapper) return;

        footerWrapper.addEventListener("click", (e) => {
            maybePreventDefault(e);
            const { target } = e;

            const link = target.closest(`
                .footer-content__partners-link,
                .footer-content__navigation-link,
                .footer__copyright-section a,
                .footer-site-logo__link
            `);
            if (!link) return;

            const linkurl = link.getAttribute('href') || "";
            const linkTextRaw = link.textContent.trim();
            const linkText = linkTextRaw.replace(/\s+/g, " ").trim() || "";

            if(link.matches('.footer-content__partners-link')){
                gtmPush({
                    event: "navigation_click",
                    navigation_type: "footer_nav",
                    click_text: "our partners",
                    click_url: linkurl,
                    nav_level: 1,
                });
            }

            if(link.matches('.footer-content__navigation-link, .footer__copyright-section a, .footer-site-logo__link')){
                gtmPush({
                    event: "navigation_click",
                    navigation_type: "footer_nav",
                    click_text: linkText,
                    click_url: linkurl,
                    nav_level: 1,
                });
            }
        });
    }
How to
To run stressberry on your computer, simply install it with

[sudo] apt install stress
python3 -m pip install stressberry
Users of Arch Linux ARM can install from the official repos

[sudo] pacman -S stressberry
and run it with

stressberry-run out.dat
stressberry-plot out.dat -o out.png
(Use MPLBACKEND=Agg stressberry-plot out.dat -o out.png if you're running the script on the Raspberry Pi itself.)

If it your computer can't find the stressberry tools after installation, you might have to add the directory $HOME/.local/bin to your path:

export PATH=$PATH:/home/pi/.local/bin
(You can also put this line in your .bashrc.)

The run lets the CPU idle for a bit, then stresses it with maximum load for 5 minutes, and lets it cool down afterwards. The entire process takes 10 minutes. The resulting data is displayed to a screen or, if specified, written to a PNG file.

If you'd like to submit your own data for display here, feel free to open an issue and include the data file, a photograph of your setup, and perhaps some further information.

Testing
To run the tests, just check out this repository and type

pytest
test('should verify typed', async () => {
  const browser = await puppeteer.launch({
    headless: false,
    slowMo: 10,
    args: ['--window-size=1920,1080']
  })
  const page = await browser.newPage()
  await page.goto(url)
  await page.type('.input-text', 'Hello World!')

  const finalText = await page.$eval('input.input-text', el => el.textContent)
  expect(finalText).toBe(finalText)
})
const {getIntroduction} = require('./util')

test('should output name and age', () => {
  const text = getIntroduction('Max', 20)
  expect(text).toBe('Max is 20 years old')
})
"scripts": {
  "test": "jest",
   "start": "node index.js"
},
"devDependencies": {
  "jest": "^26.6.3"
}
# -------------------------------------------------------------------------------------------
# email retrieving script
# -------------------------------------------------------------------------------------------
#!/usr/bin/env python3

import csv
import sys


def populate_dictionary(filename):
  """Populate a dictionary with name/email pairs for easy lookup."""
  email_dict = {}
  with open(filename) as csvfile:
    lines = csv.reader(csvfile, delimiter = ',')
    for row in lines:
      name = str(row[0].lower())
      email_dict[name] = row[1]
  return email_dict

def find_email(argv):
  """ Return an email address based on the username given."""
  # Create the username based on the command line input.
  try:
    fullname = str(argv[1] + " " + argv[2])
    # Preprocess the data
    email_dict = populate_dictionary('/home/{{ username }}/data/user_emails.csv')
     # If email exists, print it
    if email_dict.get(fullname.lower()):
      return email_dict.get(fullname.lower())
    else:
      return "No email address found"
  except IndexError:
    return "Missing parameters"

def main():
  print(find_email(sys.argv))

if __name__ == "__main__":
  main()


# -------------------------------------------------------------------------------------------
# Unit test script
# -------------------------------------------------------------------------------------------

#!/usr/bin/env python3

import unittest
from emails import find_email


class EmailsTest(unittest.TestCase):
  def test_basic(self):
    testcase = [None, "Bree", "Campbell"]
    expected = "breee@abc.edu"
    self.assertEqual(find_email(testcase), expected)

  def test_one_name(self):
    testcase = [None, "John"]
    expected = "Missing parameters"
    self.assertEqual(find_email(testcase), expected)

  def test_two_name(self):
    testcase = [None, "Roy","Cooper"]
    expected = "No email address found"
    self.assertEqual(find_email(testcase), expected)

if __name__ == '__main__':
  unittest.main()

star

Thu Jan 15 2026 03:58:28 GMT+0000 (Coordinated Universal Time)

#preventdefault #testing
star

Thu Jan 15 2026 03:56:34 GMT+0000 (Coordinated Universal Time)

#preventdefault #testing
star

Mon Apr 04 2022 15:21:45 GMT+0000 (Coordinated Universal Time) https://github.com/nschloe/stressberry

#testing
star

Sat Feb 19 2022 13:02:25 GMT+0000 (Coordinated Universal Time) https://blog.bitsrc.io/improve-react-performance-using-lazy-loading-and-suspense-933903171954

#react #testing #performance
star

Sat May 15 2021 10:50:38 GMT+0000 (Coordinated Universal Time)

#jest #nodejs #testing #puppeteer
star

Sat May 08 2021 17:59:57 GMT+0000 (Coordinated Universal Time)

#jest #nodejs #testing
star

Sat May 08 2021 17:24:35 GMT+0000 (Coordinated Universal Time)

#jest #nodejs #testing
star

Sun Mar 28 2021 07:25:37 GMT+0000 (Coordinated Universal Time)

#python #testing

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension