Skip to content

Instantly share code, notes, and snippets.

View jakub-g's full-sized avatar
💭
I may be slow to respond.

jakub-g jakub-g

💭
I may be slow to respond.
  • Antibes, France
  • 02:38 (UTC +02:00)
View GitHub Profile
@jakub-g
jakub-g / async-defer-module.md
Last active May 6, 2024 16:18
async scripts, defer scripts, module scripts: explainer, comparison, and gotchas

<script> async, defer, async defer, module, nomodule, src, inline - the cheat sheet

With the addition of ES modules, there's now no fewer than 24 ways to load your JS code: (inline|not inline) x (defer|no defer) x (async|no async) x (type=text/javascript | type=module | nomodule) -- and each of them is subtly different.

This document is a comparison of various ways the <script> tags in HTML are processed depending on the attributes set.

If you ever wondered when to use inline <script async type="module"> and when <script nomodule defer src="...">, you're in the good place!

Note that this article is about <script>s inserted in the HTML; the behavior of <script>s inserted at runtime is slightly different - see Deep dive into the murky waters of script loading by Jake Archibald (2013)

@jakub-g
jakub-g / cleanEmptyFoldersRecursively.js
Created April 3, 2015 15:31
nodejs: remove empty directories recursively
function cleanEmptyFoldersRecursively(folder) {
var fs = require('fs');
var path = require('path');
var isDir = fs.statSync(folder).isDirectory();
if (!isDir) {
return;
}
var files = fs.readdirSync(folder);
@jakub-g
jakub-g / double-fetch-triple-fetch.md
Last active April 13, 2024 12:22
Will it double-fetch? Browser behavior with `module` / `nomodule` scripts
@jakub-g
jakub-g / mac-pain.md
Last active March 20, 2024 08:53
MacOS for Windows users: overcoming the annoyances

Introduction

For a long time Windows user, starting using Mac can be an exercise in frustration and keeping your nerves at bay. Many things don't work as expected, need to be activated in some ways, keyboard shortcuts are non-existent or wildly different.

This page is a living reference of a Windows long-timer trying to do basic stuff on a Mac. If you see an easier way to achieve certain things, don't hesitate to drop a comment.

Related links:

@jakub-g
jakub-g / git-diff-stat-sort.sh
Last active March 7, 2024 01:07
sort git diff --stat starting from the files that have most lines changed
git show HEAD --stat=200 | tail +7 | awk '{ print $3 " "$4 " " $1}' | sort -n -r | less
@jakub-g
jakub-g / javascript-to-typescript-cheatsheet.md
Last active February 14, 2024 00:50
Migrate/convert JavaScript to TypeScript cheatsheet

Relevant official docs

Migrating NodeJS CJS files (require, module.exports)

First steps

  1. Rename the file from .js to .ts
  2. Change module.exports = to export =
  3. Change all exports.foobar = to export const foobar =
  4. Update top-level require calls to static import.
@jakub-g
jakub-g / readme.md
Last active January 17, 2024 16:57
Microsoft Sculpt Ergonomic Keyboard x MacOS x Karabiner settings
@jakub-g
jakub-g / md5-nodejs.js
Created October 26, 2023 12:43
md5 nodejs
let md5 = str => require('crypto').createHash('md5').update(str).digest("hex")
@jakub-g
jakub-g / _1_"script async defer" blocks "load" event.md
Last active August 22, 2023 10:10
Beware of "script async defer" blocking HTML "load" event

Beware of <script async defer> blocking HTML "load" event

2015.10.07 t

On the importance of simulated latency testing, and bulletproofing your page from the third-party JS load failures

TL;DR

@jakub-g
jakub-g / gist:b7b54852011dfd8d708fa88300452f5a
Created May 12, 2020 09:49
Samsung TV browser and Samsung TV webview useragent strings
Samsung Browser:
----------------
Mozilla/5.0 (SMART-TV; Linux; Tizen 5.0) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/2.2 Chrome/63.0.3239.84 TV Safari/537.36
Mozilla/5.0 (SMART-TV; Linux; Tizen 4.0) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/2.1 Chrome/56.0.2924.0 TV Safari/537.36
Samsung WebView:
----------------
Mozilla/5.0 (SMART-TV; LINUX; Tizen 5.0) AppleWebKit/537.36 (KHTML, like Gecko) Version/5.0 TV Safari/537.36