Skip to content

Instantly share code, notes, and snippets.

View nucliweb's full-sized avatar

Joan León nucliweb

View GitHub Profile
@anniesullie
anniesullie / CumulativeLayoutShiftBookmarklet.js
Last active February 13, 2023 07:52
Bookmarklet for showing Cumulative Layout Shift
/**
* A bookmarklet for viewing shifted elements while debugging
* Cumulative Layout Shift (web.dev/cls). Works in Chrome 84+
* Shows the previous position of shifted elements in yellow,
* and the new position in red.
*
* To install:
* 1. Copy the code starting from the line beginning `javascript:`
* 2. Add a new bookmark in Chrome, and paste the code in as the URL.
**/
@witmin
witmin / ffmpeg-mp4-to-animated-webp.md
Last active April 20, 2024 23:49
Convert MP4 file to animated WebP in ffmpeg

Convert MP4 file to animated WEBP file in ffmpeg CLI

1. Install ffmpeg CLI through homebrew

In terminal.app, install ffmpeg through homebrew

brew install ffmpeg

Validate the installation:

@pragdave
pragdave / clapperboard.js
Created April 18, 2020 23:00
Trivial JS function to help sync sound and screen when recording a browser based screencast
export function clapperBoard() {
let audio = new AudioContext()
let beep = audio.createOscillator()
let flash = document.createElement("div")
beep.frequency.value = 440 * 5
beep.connect(audio.destination)
flash.classList.add("clapperboard")
beep.start()
@addyosmani
addyosmani / custom-metrics.js
Created April 3, 2020 16:49
custom-metrics.js
[lcp]
const po = new PerformanceObserver(() => {});
po.observe({type: 'largest-contentful-paint', buffered: true});
const lastEntry = po.takeRecords().slice(-1)[0];
return lastEntry.renderTime || lastEntry.loadTime;
[cls]
const po = new PerformanceObserver(() => {});
po.observe({type: 'layout-shift', buffered: true});
return po.takeRecords().reduce((val, entry) => val + entry.value, 0);
@addyosmani
addyosmani / lcp.js
Last active March 26, 2024 00:09
Largest Contentful Paint - Puppeteer
const puppeteer = require('puppeteer');
const Good3G = {
'offline': false,
'downloadThroughput': 1.5 * 1024 * 1024 / 8,
'uploadThroughput': 750 * 1024 / 8,
'latency': 40
};
const phone = puppeteer.KnownDevices['Nexus 5X'];
@tomhicks
tomhicks / plink-plonk.js
Last active March 18, 2024 02:23
Listen to your web pages
@mattdesl
mattdesl / about.md
Last active December 15, 2023 17:45
png + svg export with canvas-sketch and context 2D

PNG + SVG export from canvas-sketch

The helper function canvas-to-svg.js wraps a given render function (or renderer object) so that you can use Canvas2D context methods as usual, but upon single frame export (with Cmd/Ctrl + S) it will produce both a PNG and SVG file.

This uses canvas2svg which is not a perfect solution, as the Canvas2D API was never designed to be translated to SVG. Its best to stick with simple shape and path operations.

Full instructions: first install the canvas-sketch CLI if you haven't already:

npm install canvas-sketch-cli -g
@una
una / color-functions.md
Last active March 11, 2020 13:15
CSS Color Functions

CSS Color Functions

Web developers and design systems developers often use functions to design components. With the increasing usage of design systems that support multiple platforms, and increased capability of Dark Mode in UI, this becomes even more useful to not need to manually set color, and to instead have a single source from which layouts are calculated. Currently Sass, calc() on HSL values, or PostCSS is used to do this.

Examples:

  • Components with color variations based on calculations from a parent. (i.e. Button with outline that uses the primary button color to adjust the size)
  • Theming - Palletes based on a color or set of colors for themes. Especially when a single base system is used with multiple themes
  • Uniformity among transformations between components with different primary colors

Proposal

@marcosvpj
marcosvpj / vscode-remove-duplicate-lines.md
Last active March 22, 2024 13:41
How to remove duplicate lines in Visual Studio Code?

If the order of lines is not important##

Sort lines alphabetically, if they aren't already, and perform these steps:
(based on this related question: https://stackoverflow.com/q/1573361/3258851)

  1. Control+F

  2. Toggle "Replace mode"

  3. Toggle "Use Regular Expression" (the icon with the .* symbol)

@ntkog
ntkog / propuestas.js
Created April 18, 2019 09:57
Propuestas Partidos políticos según newtral
function propuestas(partido) {
let lista = [...document.querySelectorAll('.e-module div[data-option]')].map(el=>({
partido: el.dataset.option,
texto: [...el.querySelectorAll('p')].reduce((old,cur)=>old + cur.textContent, "")
})).filter(obj=> (partido === "all" ? true : obj.partido === partido) && obj.texto.length > 0);
partido === "all" ? console.table(lista) : console.table(lista,["texto"]);
let csv = lista.map(r => `"${r.partido}"|"${r.texto.replace(/\n/g, " ")}"`);
csv.unshift(`"partido"|"texto"`);
// Copia al portapapeles todos los datos a un CSV