Skip to content

Instantly share code, notes, and snippets.

@cangoektas
cangoektas / comparison.md
Last active November 10, 2018 01:21
Core rule settings of popular ESLint configs

Core rule settings of popular ESLint configs

An overview of how popular ESLint configs use the latest core rules. The rules are listed in the order they appear on the ESLint rules page: https://eslint.org/docs/rules/.

Configs

Name Weekly NPM Downloads
eslint:recommended (installed with ESLint)
airbnb         699,637          
@gaearon
gaearon / prepack-gentle-intro-1.md
Last active February 13, 2024 14:30
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@ebidel
ebidel / coverage.js
Last active September 24, 2023 10:25
CSS/JS code coverage during lifecycle of page load
Moved to https://github.com/ebidel/puppeteer-examples
@ebidel
ebidel / sw_caching_size.js
Last active November 16, 2022 11:31
Print service worker cache sizes and overall bytes cached.
/**
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
*/
// Prints the bytes cached by service worker. Breaks out each cache
// overall in-memory bytes used by the Cache Storage API for the site.
async function getCacheStoragesAssetTotalSize() {
// Note: opaque (i.e. cross-domain, without CORS) responses in the cache will return a size of 0.
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: view.topAnchor),

Motivation

  • expression-oriented programming one of the great advances of FP
  • expressions plug together like legos, making more malleable programming experience in-the-small

Examples

Write in an expression-oriented style, scoping variables as locally as possible:

@Rich-Harris
Rich-Harris / footgun.md
Last active March 7, 2024 08:12
Top-level `await` is a footgun

Edit — February 2019

This gist had a far larger impact than I imagined it would, and apparently people are still finding it, so a quick update:

  • TC39 is currently moving forward with a slightly different version of TLA, referred to as 'variant B', in which a module with TLA doesn't block sibling execution. This vastly reduces the danger of parallelizable work happening in serial and thereby delaying startup, which was the concern that motivated me to write this gist
  • In the wild, we're seeing (async main(){...}()) as a substitute for TLA. This completely eliminates the blocking problem (yay!) but it's less powerful, and harder to statically analyse (boo). In other words the lack of TLA is causing real problems
  • Therefore, a version of TLA that solves the original issue is a valuable addition to the language, and I'm in full support of the current proposal, which you can read here.

I'll leave the rest of this document unedited, for archaeological

@Rich-Harris
Rich-Harris / service-workers.md
Last active March 28, 2024 23:58
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@adrianholovaty
adrianholovaty / service-worker-cache-example.js
Last active May 5, 2020 21:25
Better example of custom service worker cache keys
var jsonDataRe = /example\.com\/(.*\.json)/;
self.addEventListener('fetch', function(event) {
var request = event.request,
match = jsonDataRe.exec(request.url);
if (match) {
// Use regex capturing to grab only the bit of the URL
// that we care about, ignoring query string, etc.
var cacheRequest = new Request(match[1]);
@cobyism
cobyism / gh-pages-deploy.md
Last active March 20, 2024 02:20
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).