Skip to content

Instantly share code, notes, and snippets.

View sgelob's full-sized avatar
🐻

Olegs Belousovs sgelob

🐻
View GitHub Profile
@ole-boss
ole-boss / Big Query Google Analytics sessions export including site speed metrics.sql
Last active June 13, 2020 14:41
This script helps you creating sessions from Google Analytics raw data on hit level in Google Big Query. The export will also include some metrics related to site speed based on Google's Latency Tracking KPIs.
SELECT
first_sessions.sid AS sessionId,
visitorId,
first_transactions.transactionId AS transactionId,
timestamp,
deviceCategory,
landingPage,
pageviews,
timeOnSite,
channel,
@nicjansma
nicjansma / resourcetiming-iframe.js
Last active May 30, 2020 21:23
ResourceTiming leak to parent frames
//
// Placed in any cross-origin IFRAMEs
//
if (window !== window.top) {
if (typeof window.PerformanceObserver !== "function") {
return;
}
// Listen for all ResourceTimings, repeating them to the parent window
var observer = new PerformanceObserver(function(entries) {
@nicjansma
nicjansma / resourcetiming-crawl.js
Last active July 23, 2018 15:27
Naive ResourceTiming crawl of all IFRAMEs
//
// Naive ResourceTiming crawl of all IFRAMEs.
//
// Based on https://github.com/SOASTA/boomerang/blob/master/plugins/restiming.js
// which you should use to deal with all of the caveats (e.g. startTime adjusting)
//
function isFrameAccessible(frame) {
var dummy;
<img srcset="https://assets.imgix.net/flower.jpg?w=50 50w,
https://assets.imgix.net/flower.jpg?w=100 100w,
https://assets.imgix.net/flower.jpg?w=150 150w,
...
https://assets.imgix.net/flower.jpg?w=5200 5200w,
https://assets.imgix.net/flower.jpg?w=5260 5260w"
src="https://assets.imgix.net/flower.jpg?w=540"
alt="A white flower"
/>
@jgrahamc
jgrahamc / index.php
Last active June 18, 2020 09:38
Demonstrating how to use Link headers to make CloudFlare push assets
<?php
function ccbysa($imagehtml, $sourceuri, $owneruri, $ownername) {
return <<<HTML
{$imagehtml}
<br/>
<small><a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>
<a href="{$sourceuri}">image</a> by <a href="{$owneruri}">{$ownername}</a>
<br/>
HTML;
@chrisgoddard
chrisgoddard / json-ld-gtm.html
Last active July 23, 2023 16:52
JSON-LD GTM Tag
<script>
(function(){
var data = {
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{Page URL}}
},
"headline": {{SCHEMA - Article Headline}},
@ctlcltd
ctlcltd / wordpress_low-quality-image-placeholders_lqip.md
Last active June 22, 2023 20:08
How to easily generate low quality image placeholders (lqip) in WordPress

How to easily generate low quality image placeholders (lqip) in WordPress

I have made this function using the WP_Image_Editor class and I have filtered through the "wp_generate_attachment_metadata" hook. You can modify the "theme" namespace into function names with your theme name or in anyway you like.

Applying the filter directly to wp_generate_attachment_metadata the image placeholders are auto added into WordPress metadata, so when your add/modify/delete an image (or regenerate it via a plugin), it accomplishes to modify also to the image placeholders.

The use of the native theme support can prevent the generation of lqip or target specific image sizes to generate.

It contains an hook filter lqip_quality to modify the quality without have to modify the function.

@adactio
adactio / basicServiceWorker.js
Last active March 27, 2023 09:30
A basic Service Worker, for use on, say, a blog.
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function() {
// Update 'version' if you need to refresh the cache
var staticCacheName = 'static';
var version = 'v1::';
@doismellburning
doismellburning / userstories.md
Last active October 30, 2017 16:25
Conference User Stories
@james-Ballyhoo
james-Ballyhoo / critcss.snippet.js
Created September 18, 2015 08:34
Based off of https://gist.github.com/PaulKinlan/6284142 , but with support for media queries and dumps css to a textarea in a panel stuck to the top of the page. Only tested in Chrome, uses height of window to determine "critical path".
(function(){
if(document.querySelector("#_CRIT_CSS")){return;}
var container = document.createElement("div");
container.id = "_CRIT_CSS";
container.innerHTML = '<textarea cols=80 rows=20></textarea><button id="CRIT_FIND">Find Critical CSS</button><button id="CRIT_CLOSE">Exit</button>';
container.style.position = "fixed";
container.style.top = 0;
container.style.left = 0;
container.style.right = 0;
container.style.backgroundColor = "#FFF";