Skip to content

Instantly share code, notes, and snippets.

function camelToKebab(string) {
const tag = document.createElement('span')
tag.dataset[string] = true
return tag.attributes[0].name.split(/^data-/)[1]
}
let _str = (function(){
const tag = document.createElement('span')
return {
propToAttr: (string) {
tag.dataset[string] = true
return tag.attributes[0].name.split(/^data-/)[1]
},
attrToProp(string) {
tag.setAttribute(`data-${string}`, true)
return Object.entries(tag.dataset)[0][0]
@paulirish
paulirish / what-forces-layout.md
Last active May 6, 2024 05:08
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@Rich-Harris
Rich-Harris / geojson.md
Last active May 6, 2024 05:08
A better GeoJSON

A better GeoJSON

GeoJSON is a widely-used format for encoding geographic data. It's flexible and human-readable, and because it's just JSON it's easy to integrate into web applications.

But it has some real warts, and if we wanted to we could certainly come up with a better format. After tweeting about my frustrations, I was asked to elaborate. Here goes:

Redundancy

GeoJSON geometries can be one of seven types: Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon and GeometryCollection.

@dauwhe
dauwhe / toast.md
Last active May 6, 2024 05:08
Are Web Standards Toast?

Are Web Standards Toast?

I find myself in a tempest in a toaster. Yesterday I (and much of the web standards world) learned about two possible new HTML elements proposed by Google, std-toast and std-switch. I had no idea what “toast” meant in the context of the web, a problem shared my many other people. It turns out it’s a UI pattern, those little notices that pop up and then disappear without user interaction.

But wow, new HTML elements! This is the holy grail. In my part of the web we don’t even dream about new HTML elements. Oh, we’ve tried, but Hixie didn’t much care for footnote, WICG didn’t much care for list titles, and no one much cared about author. Just last week the author of the extensible web manifesto warned me to never expect new HTML elements, due to the difficulty of changing the parser.

But my concern wasn’t so much about the nature of the new elements, but of how we learned about them and what that says about how web standardization works. My [first tweet](https://twitter.com

@prushforth
prushforth / index.html
Created December 17, 2018 14:50
leaflet 1.3.4, proj4leaflet 1.0.2 and epsg:3978 use with CBMT tile cache
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="leaflet/leaflet.css" />
</head>
<body>
<div id="map"></div>
<script src="leaflet/leaflet.js"></script>

Think about how rules are written, applied and work.

In talking about a tree, you have very few basic constructs: Element name, attribute, ancestor/descendant relationships.

You write a CSS selector like .foo bar * bat. These are based on, effectively, element names and attributes (tho there are some 'special' kinds of attributes like ID which is really just an attribute with unusually high specificity and class which is really just an attribute that contains a serialized DOMTokenList). Aside from these the only other thing in your vernacular is "descendant of" or "child of" or some few things about your immediate siblings.

Now, think about when the document is parsing, what does the browser have to do? At some point, it needs to figure out "which rules apply to this element right now" and then make sure that they are applied, in specificity order so that it can figure out what to paint.

Let's imagine that you have a few hundred rules, that's not entirely unusual. Let's imagine that your DOM

@bkardell
bkardell / declarative-resize-observer.js
Last active May 6, 2024 05:06
Uses mutation observers to create a declarative `ResizeObserver` pattern based on a boolean `resize-observer` attribute. These elements track the size of their elements in batch and set a tshirt-size container attribute. If `ResizeObserver` isn't implmented, it uses a lightweight approximation. The whole thing weighs in at <1k gzipped and minified
"use strict";
(function () {
var xSizeEls = [],
custom = {
width: {},
height: {}
},
breakpoints = {
width: {

This is how great ideas often happen, they fade into view over a long period of time... The challenge for all of us is how do you create environments that allow these ideas to have this kind of long half-life, right? It's hard to go to your boss and say "I have an excellent idea for our organization. It will be useful in 2020 [about a decade at the time of this recording], uh, could you just give me some time to do that?."

@shvchk
shvchk / xiaomi-bloatware.txt
Created July 25, 2023 05:45
Xiaomi MIUI debloat list. Initially made for Poco M5, but will probably work fine for any recent Xiaomi phone
com.android.bips
com.android.bookmarkprovider
com.android.printspooler
com.android.providers.partnerbookmarks
com.android.stk
com.android.traceur
com.bsp.catchlog
com.facebook.appmanager
com.facebook.services
com.facebook.system