Skip to content

Instantly share code, notes, and snippets.

View mlarocca's full-sized avatar

Marcello La Rocca mlarocca

View GitHub Profile
@Rich-Harris
Rich-Harris / footgun.md
Last active April 19, 2024 07:47
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 April 21, 2024 16:24
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.

@mlarocca
mlarocca / chart_utils.js
Last active December 9, 2015 22:48
Dynamic Charts Showcase - by Marcello La Rocca
if (!window.ChartUtils){
/**
Module ChartUtils
Extends Object class with several useful methods to allow better encapsulation mechanisms.<br>
Exposes a few utility functions
@module ChartUtils
*/
@mlarocca
mlarocca / chart_utils.js
Last active December 9, 2015 22:39
Dynamically populated charts - by Marcello La Rocca
if (!window.ChartUtils){
/**
Module ChartUtils
Extends Object class with several useful methods to allow better encapsulation mechanisms.<br>
Exposes a few utility functions
@module ChartUtils
*/
@mlarocca
mlarocca / sudoku_profiler.py
Created December 15, 2012 00:01
Sudoku solution checker
'''
Created on 15/dic/2012
@author: mlarocca
'''
from sudoku_solver import solve_sudoku
super_hard = [[0,0,3,0,0,5,4,1,0],
[0,0,0,1,0,0,0,8,5],
[0,0,0,3,0,0,6,0,0],
[0,0,0,0,3,0,0,6,0],