Skip to content

Instantly share code, notes, and snippets.

View bluwy's full-sized avatar
♥️
【=◈︿◈=】

Bjorn Lu bluwy

♥️
【=◈︿◈=】
View GitHub Profile
@bluwy
bluwy / GitHub Delete Issues.user.js
Last active May 23, 2024 09:32
Userscript to add a delete issue button in the issues page. It opens the issue in a new tab, delete it, and auto-close the tab (sometimes not working). There's also a button to delete all issues in the current page, which opens all the tabs at once. Also works for discussions. BEWARE that deleting issues is not reversible!
// ==UserScript==
// @name GitHub Delete Issues
// @license MIT
// @version 0.1.0
// @description Adds buttons to easily delete issues
// @author bluwy
// @match https://github.com/**
// @grant none
// ==/UserScript==
@bluwy
bluwy / publint_analysis.json
Last active December 22, 2024 04:04
Results of publint's analysis script (force push only)
{
"semver@7.6.3": 1,
"ansi-styles@6.2.1": 0,
"debug@4.4.0": 1,
"supports-color@10.0.0": 0,
"chalk@5.4.1": 0,
"ms@2.1.3": 1,
"tslib@2.8.1": 1,
"has-flag@5.0.1": 0,
"minimatch@10.0.1": 1,
@bluwy
bluwy / rollup-optimization-research.md
Last active October 11, 2024 15:20
Rollup build optimization research

Rollup build optimization research

Rollup builds doesn't scale well in large apps. You need to increase Node's memory with --max-old-space-size=4096 to handle all the modules. This is one of Vite's highest-rated issue.

This file documents various findings and attempts to improve this issue.

How Rollup works

NOTE: I've only been reading Rollup's source code for a while, so some of these may not be accurate.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bluwy
bluwy / sequence.js
Last active March 29, 2022 03:42
Run Svelte preprocessors in the sequence they are declared
import { preprocess } from 'svelte/compiler'
/**
* @typedef {import("svelte/types/compiler/preprocess").PreprocessorGroup} PreprocessorGroup
* @param {PreprocessorGroup[]} preprocessors
* @returns {PreprocessorGroup[]}
*/
export function sequence(preprocessors) {
return preprocessors.map((preprocessor) => ({
markup({ content, filename }) {
@bluwy
bluwy / reloadImgOnFail.js
Created July 10, 2021 12:48
[Svelte] Reload image on fail to fetch
export function reloadImgOnFail(img, opts = {}) {
opts = ensureOpts(opts)
let retryCount = 0
function handleError() {
if (retryCount >= opts.maxRetryCount) {
if (opts.fallbackSrc && img.src !== opts.fallbackSrc) {
img.src = opts.fallbackSrc
}
@bluwy
bluwy / svelte-preprocess-svg.js
Last active May 30, 2021 07:15
Load SVGs as Svelte components with the least runtime overhead. Not sure if this actually improve performance?
export default function sveltePreprocessSvg() {
return {
markup({ content }) {
content = content.trim()
if (content.startsWith('<svg ') && content.endsWith('</svg>')) {
return { code: `{@html \`${content}\`}` }
} else {
return { code: content }
}
},
@bluwy
bluwy / vite.config.js
Created May 4, 2021 15:52
Import SVG as Svelte component
import fs from 'fs/promises'
import { defineConfig } from 'vite'
import svelte from '@sveltejs/vite-plugin-svelte'
export default defineConfig({
plugins: [svelteSvgPlugin(), svelte({ extensions: ['.svelte', '.svg'] })],
})
function svelteSvgPlugin() {
return {
@bluwy
bluwy / clean-snaps.sh
Created May 4, 2021 06:18
Remove unused snaps
#!/bin/bash
# Removes old revisions of snaps
# CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=C snap list --all | awk '/disabled/{print $1, $3}' |
while read snapname revision; do
snap remove "$snapname" --revision="$revision"
done
@bluwy
bluwy / ghaction-publish.md
Created January 24, 2021 05:25
GitHub Actions publish flow

Assuming

  1. Latest version is v1
  2. Real underlying version is v1.0.0
  3. A new release is to be published at v1.0.1 and v1

Steps

  1. Push commits
  2. Create new release for v1.0.1