Skip to content

Instantly share code, notes, and snippets.

@samthor
samthor / safari-nomodule.js
Last active January 15, 2026 17:50
Safari 10.1 `nomodule` support
// UPDATE: In 2023, you should probably stop using this! The narrow version of Safari that
// does not support `nomodule` is probably not being used anywhere. The code below is left
// for posterity.
/**
* Safari 10.1 supports modules, but does not support the `nomodule` attribute - it will
* load <script nomodule> anyway. This snippet solve this problem, but only for script
* tags that load external code, e.g.: <script nomodule src="nomodule.js"></script>
*
* Again: this will **not** prevent inline script, e.g.:
@shspage
shspage / draw_arc.jsx
Last active October 3, 2017 21:47
Illustrator : 2点をつなぐ弧を描く
// 3つのオブジェクト(前面からp1, p2, o)が選択されているとき、
// p1の中心からp2の中心へ反時計回りに弧を描く。
// o の中心を弧の中心とする。
// ----------------------------------------------
// 点
// x, y : float
var Point = function(x, y){
this.x = x;
this.y = y;
}
node_modules
@gkhays
gkhays / DrawSineWave.html
Last active January 21, 2026 21:36
Oscillating sine wave, including the steps to figuring out how to plot a sine wave
<!DOCTYPE html>
<html>
<head>
<title>Sine Wave</title>
<script type="text/javascript">
function showAxes(ctx,axes) {
var width = ctx.canvas.width;
var height = ctx.canvas.height;
var xMin = 0;
@Rich-Harris
Rich-Harris / imperative-v-declarative-imports.md
Last active May 6, 2024 10:23
Why imperative imports are slower than declarative imports

Why imperative imports are slower than declarative imports

A lot of people misunderstood Top-level await is a footgun, including me. I thought the primary danger was that people would be able to put things like AJAX requests in their top-level await expressions, and that this was terrible because await strongly encourages sequential operations even though a lot of the asynchronous activity we're talking about should actually happen concurrently.

But that's not the worst of it. Imperative module loading is intrinsically bad for app startup performance, in ways that are quite subtle.

Consider an app like this:

// main.js
@adamreisnz
adamreisnz / package.json
Last active April 12, 2025 09:09
Simple pure npm scripts build process
{
"name": "project-name",
"description": "Template for static sites",
"version": "1.0.0",
"homepage": "http://www.project-name.com",
"author": {
"name": "Adam Reis",
"url": "http://adam.reis.nz"
},
"license": "UNLICENSED",
@Rich-Harris
Rich-Harris / service-workers.md
Last active February 24, 2026 02:06
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.

@shspage
shspage / voronoi-example.jsx
Last active October 18, 2016 09:30
Adobe Illustrator script that draws voronoi diagrams - example (commented in Japanese)
//@include "~/ailib/rhill-voronoi-core.js"
// Adobe Illustrator script
// 選択した各オブジェクトの中心の座標を元にボロノイ図を描画します。
// 描画範囲は選択オブジェクト中で面積が最大のものを使用します。
// (このため、外枠となるオブジェクトも選択範囲に含めてください。
// 外枠はボロノイ計算の対象外です。)
// 描画した線はグループ化されています。
// 塗りのある面を描画しない場合は、スクリプト冒頭の
// DRAW_POLYGONS を false にしてください。
@enghqii
enghqii / SAT.js
Last active April 28, 2024 23:58
SAT (Separating Axis Theorem) collision detection using PIXI.js
// initializing
var renderer = PIXI.autoDetectRenderer(800, 600, { antialias: true, backgroundColor : 0xf7f7f7 });
renderer.view.style.borderStyle = "solid";
renderer.view.style.borderColor = "#bbbbbb";
renderer.view.style.borderWidth = "1px";
document.body.appendChild(renderer.view);
// create the root of the scene graph
var stage = new PIXI.Container();
stage.interactive = true;
@rpggio
rpggio / PaperJSViewZoom.ts
Last active December 25, 2019 11:23
An implementation of pan and zoom in Paper.js, based on http://matthiasberth.com/articles/stable-zoom-and-pan-in-paperjs/. Requires jquery-mousewheel to capture wheel events.
class ViewZoom {
project: paper.Project;
factor = 1.25;
private _minZoom: number;
private _maxZoom: number;
private mouseNativeStart: paper.Point;
private viewCenterStart: paper.Point;