Skip to content

Instantly share code, notes, and snippets.

View nucliweb's full-sized avatar

Joan León nucliweb

View GitHub Profile
@nucliweb
nucliweb / async-defer-module.md
Created May 21, 2024 19:54 — forked from jakub-g/async-defer-module.md
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)

@nucliweb
nucliweb / speculationrules.js
Created May 19, 2024 18:25
Speculation Rules Script
if (HTMLScriptElement.supports?.('speculationrules')) {
const specScript = document.createElement('script')
specScript.type = 'speculationrules'
const specRules = {
prerender: [{
urls: ['/next.html'],
}, ],
}
specScript.textContent = JSON.stringify(specRules)
document.body.append(specScript)
@nucliweb
nucliweb / Switch-Node-Version.sh
Last active October 6, 2023 15:42
Zsh script to switch to Node defined in the .nvmrc file.
# place this after nvm initialization!
autoload -U add-zsh-hook
load-nvmrc() {
local nvmrc_path
nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version
nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
@nucliweb
nucliweb / function.sh
Created September 15, 2023 21:49
List and select npm scripts
## Requisites
## fzf https://github.com/junegunn/fzf
## jq https://jqlang.github.io/jq/
_nr () {
local cmd
local TASK=$(npm run | egrep '^\s' | awk '{gsub(/ /,""); print}' | awk 'NR%2==1' | fzf --preview 'jq .scripts package.json' | awk '{gsub(/ /,""); print}')
if [ -n "$TASK" ]; then
cmd="npm run \"$TASK\""
eval "$cmd" &
@nucliweb
nucliweb / rust-command-line-utilities.markdown
Created September 6, 2023 19:20 — forked from sts10/rust-command-line-utilities.markdown
A curated list of command-line utilities written in Rust

A curated list of command-line utilities written in Rust

Note: I have moved this list to a proper repository. I'll leave this gist up, but it won't be updated. To submit an idea, open a PR on the repo.

Note that I have not tried all of these personally, and cannot and do not vouch for all of the tools listed here. In most cases, the descriptions here are copied directly from their code repos. Some may have been abandoned. Investigate before installing/using.

The ones I use regularly include: bat, dust, fd, fend, hyperfine, miniserve, ripgrep, just, cargo-audit and cargo-wipe.

  • atuin: "Magical shell history"
  • bandwhich: Terminal bandwidth utilization tool
@nucliweb
nucliweb / ffmpeg-mp4-to-animated-webp.md
Created August 10, 2023 05:24 — forked from witmin/ffmpeg-mp4-to-animated-webp.md
Convert MP4 file to animated WebP in ffmpeg

Convert MP4 file to animated WEBP file in ffmpeg CLI

1. Install ffmpeg CLI through homebrew

In terminal.app, install ffmpeg through homebrew

brew install ffmpeg

Validate the installation:

@nucliweb
nucliweb / CumulativeLayoutShiftBookmarklet.js
Last active February 13, 2023 07:53 — forked from anniesullie/CumulativeLayoutShiftBookmarklet.js
Bookmarklet for showing Cumulative Layout Shift
/**
* A bookmarklet for viewing shifted elements while debugging
* Cumulative Layout Shift (web.dev/cls). Works in Chrome 84+
* Shows the previous position of shifted elements in yellow,
* and the new position in red.
*
* To install:
* 1. Copy the code starting from the line beginning `javascript:`
* 2. Add a new bookmark in Chrome, and paste the code in as the URL.
**/
@nucliweb
nucliweb / download_all_branches.sh
Created September 18, 2022 17:47 — forked from doulmi/download_all_branches.sh
Download All branches
#!/bin/bash
set -x #echo on
remote_url=$(git config --get remote.origin.url)
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
branch_name=$(echo $branch| cut -d'/' -f 3)
git clone -b $branch_name $remote_url $branch_name
done
@nucliweb
nucliweb / Install-OpenCV-Mac-M1.md
Last active May 12, 2024 18:07
OpenCV C++ Mac M1 Installation Steps
const puppeteer = require("puppeteer");
// const crawlPage = require("./crawl-urls");
const PAGE_URL = process.argv[2] || "https://pptr.dev";
const bytesToSize = (bytes, decimals = 2) => {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;