Skip to content

Instantly share code, notes, and snippets.

View jakub-g's full-sized avatar

jakub-g jakub-g

  • Antibes, France
  • 04:59 (UTC +02:00)
View GitHub Profile
@jakub-g
jakub-g / async-defer-module.md
Last active July 23, 2024 21:22
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 / git-diff-stat-sort.sh
Last active July 20, 2024 09:17
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 / hn.md
Last active June 2, 2024 23:29
Hacker News Links

Hacker News "hidden" URLs

Many of HN URLs are not easily discoverable as there are no links to them in a prominent part on the page, or sometimes even nowhere. The following is a list of links to standard and "special" HN pages. The ones is bold are the less discoverable ones.

See also: https://github.com/minimaxir/hacker-news-undocumented

Posts

@jakub-g
jakub-g / github-code-search-syntax.md
Created February 17, 2021 08:13
Searching files on GitHub

GitHub search docs: here

  • org:ORGNAME to filter down to org
  • org:ORGNAME -repo:ORGNAME/NOISY to filter out some repos
  • path:PATH to search by location
  • language:... or extension:... to filter by lang/extension
  • in:file, in:path, in:file,path to include contents or file paths
@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 / 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")