Skip to content

Instantly share code, notes, and snippets.

View appelgran's full-sized avatar

appelgran

View GitHub Profile
@appelgran
appelgran / perf.js
Last active September 29, 2023 11:16
perf.js from Philip Walton's video A deep dive into optimizing LCP
new PerformanceObserver((list) => {
const lcpEntry = list.getEntries().at(-1);
if (!lcpEntry.url) {
// In case LCP is a <p> or <h1> etc (not a resource w url)
console.log('LCP: ', lcpEntry.startTime, lcpEntry.element);
console.log('LCP element outerHTML: ', lcpEntry.element.outerHTML);
return;
}
const navEntry = performance.getEntriesByType('navigation')[0];
@appelgran
appelgran / siblings.js
Created February 23, 2022 11:12
Vanilla javascript version of jquery siblings with selector (plus callback)
/*
Browser Compatibility:
IE: 9, Safari: 3.1, Chrome: 1, Edge: 12, Firefox: 3.5
*/
function getSiblings(el, sel) {
var matches = [];
var targets = sel ? el.parentNode.querySelectorAll(sel) : el.parentNode.children;
for (var target of targets) {
if (target !== el && target.parentNode === el.parentNode) {
matches.push(target);
@appelgran
appelgran / swiper-lazy-init.js
Created December 10, 2021 12:52
Swiper loading optimization
/*
* Include this file early and then initialize your Swipers using
* swiperLazyInit(...). Swiper lib can then be loaded async or later.
*
* Re-configure example: var slideshow = new Swiper("#slideshow", { speed: 400 });
* Becomes: swiperLazyInit("#slideshow", { speed: 400 }, function(slideshow) { });
*/
function swiperLazyInit(swiperContainer, parameters, callback) {
if (window.Swiper) {
// fix with init to break up the creation and initialization of the swiper in two parts
@appelgran
appelgran / 0.note.md
Last active April 9, 2021 08:45
PageSpeed Insights / Lighthouse and flushing

The results will be posted in comments

@appelgran
appelgran / responsive-test-tool.html
Last active April 8, 2021 09:50
Responsive test tool for easy responsiveness evaluation (like Responsinator but better) (online at https://tools.easyweb.site/responsive-test-tool.html)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Responsive test tool</title>
<style>
body {
margin: 0;
background-color: #111;
@appelgran
appelgran / garmin-connect-activity-comparison-better-splits.js
Created November 5, 2020 16:25
Garmin Connect, Activity Comparison. Better splits. #bookmarklet
// run on for example https://connect.garmin.com/modern/comparison?activityId=111&activityId2=222&activityId3=333
(function() {
function str2time(text) {
var t = text.trim().replace(',', '.').split(':').reverse();
return (parseInt(t[2]) || 0) * 3600 + (parseInt(t[1]) || 0) * 60 + (parseFloat(t[0]) || 0);
}
function time2str(time) {
var s = (time % 60).toFixed(0);
return Math.floor(time / 60) +':'+ (s < 10 ? '0' + s : s)
}
@appelgran
appelgran / news-external.b.php
Created April 16, 2020 19:29
JS/PHP - Send cache and renew cache without waiting for the renewal
<?php
//
// Outputcache
$cache_time_in_seconds = 600;
$cache_file_name = 'news-external.b.php.outputcache';
$echo_output_after_save = true;
if (file_exists($cache_file_name)) {
// Cache exists
if (time() - filemtime($cache_file_name) < $cache_time_in_seconds) {
@appelgran
appelgran / ExceptIndistinctExtensions.cs
Last active November 14, 2019 11:02
Linq Except Indistinct
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
// Credit to Alex Siepman and digEmAll on StackOverflow (answer https://stackoverflow.com/a/18321594/1049710)