Skip to content

Instantly share code, notes, and snippets.

View loilo's full-sized avatar

Florian Reuschel loilo

View GitHub Profile
@loilo
loilo / high-sierra-iso.md
Last active January 12, 2023 05:26
Create an installation ISO file for macOS High Sierra
  1. Prerequisites:
    • You need a running macOS system.
    • I assume you're familiar with using the terminal.
    • All the examples below refer to installing macOS High Sierra, you may need to adjust them to your needs if you want to install another macOS version.
  2. Download macOS High Sierra from the AppStore.
  3. The macOS installer will start after the download finiashes. We don't need it, so we can close it.
  4. We need an empty image where we'll put the installer. Let's create one using the macOS DiskUtil CLI:
    hdiutil create -o /tmp/HighSierra -size 8G -layout SPUD -fs HFS+J -type SPARSE
@loilo
loilo / compare-files.js
Last active December 2, 2022 03:43
Compare File Lists in Node.js
import revHash from 'rev-hash'
import { readFileSync, statSync } from 'fs'
import { resolve } from 'path'
/**
* Calculate the rev hash for a file
*
* @param {string} file The path to the file to hash
* @returns {string}
*/
@loilo
loilo / xpath.js
Last active November 27, 2022 11:07
Find DOM nodes via XPath
/**
* Find nodes via XPath
*
* @param {string} query
* @param {Node} root
* @returns {Node[]}
*/
export function xpath(query, root = document) {
let iterator = document.evaluate(query, document)
@loilo
loilo / zip.md
Created August 18, 2022 16:25
Simple .zip file generation with JavaScript using JSZip

Simple .zip file generation with JavaScript using JSZip

The zipTree function exported from this module takes a file tree object and creates a zip object from it using JSZip (which you need to install first via npm install jszip):

// A tree is just a collection of file names mapped to their contents
let data = {
  // Use a string for text content
  'file.txt': '...file content...',
@loilo
loilo / Debouncer.md
Last active November 21, 2022 08:24
ReactPHP debounce

ReactPHP Debouncer

A simple & classic debounce function. You provide a callable and specify a $wait timer and get a callable (closure) back.

The closure takes the same arguments as the provided callable, but will only be executed $wait seconds after being invoked. Invoking the closure again before $wait seconds have passed will refresh the execution delay to the full $wait seconds again.

This can be useful for example for detecting if a socket hasn't received data in, let's say, 10 seconds:

$loop = React\EventLoop\Factory::create();
@loilo
loilo / readme.md
Last active November 3, 2022 20:31
Async Computed Values for Vue 3

Async Computed Values for Vue 3

This gist provides a useAsyncComputed function which allows to create asynchronous dependencies on reactive values (using Vue 3's Composition API).

Requires at least Vue 3.0 and TypeScript 4.0.

Usage

Basic Usage

@loilo
loilo / plugin-extract-remote-assets.js
Created October 3, 2022 12:13
Extract Remote Assets Rollup Plugin
import { createFilter } from '@rollup/pluginutils'
import got from 'got'
import MagicString from 'magic-string'
import path from 'node:path'
import revisionHash from 'rev-hash'
function escapeRegex(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}
@loilo
loilo / LICENSE.md
Created August 16, 2022 18:29
This license applies to all of loilo's public GitHub Gists (unless otherwise specified or not eligible for copyright)
@loilo
loilo / readme.md
Last active June 27, 2022 10:10
Sort by Samples

Sort by Samples

A sorting function that takes an array of samples. All sortable items which occur in the samples will be arranged in the order they occur there, all other items will be appended to the end in their original order or sorted with an optional provided comparision algorithm.

This can be useful when the items to sort are not completely known, but there are some well-known ones that should come first:

const pages = [ 'About', 'Products', 'Home', 'Contact', 'Carreer' ]

// No idea what pages exist, but if "Home" and "About" exist, they should come first
@loilo
loilo / use-element-breakpoints.ts
Created April 28, 2022 07:46
useElementBreakpoints – Vue Composable for Element breakpoints
// useElementBreakpoints is a Vue 3 composable that matches an element's width (or height) against a set of predefined breakpoints
// It needs @vueuse/core to be installed and uses an equivalent breakpoints input as well as an equivalent returned API
import { computed, Ref } from 'vue'
import { useElementSize, MaybeElementRef } from '@vueuse/core'
export type Breakpoints<K extends string = string> = Record<K, number>
export type ElementBreakpointsOptions = { dimension: 'width' | 'height' }
/**