This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Shorten a path in PowerShell by omitting segments from the beginning. | |
| # Parameter defaults are designed to be used in a prompt. | |
| # Requires at least PowerShell Core 7. | |
| function shorten-path { | |
| <# | |
| .SYNOPSIS | |
| Shortens a path from the end. | |
| .DESCRIPTION |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Get the number of characters in an element | |
| * | |
| * @param {Element} element | |
| * @return {number} | |
| */ | |
| function getTextLength(element) { | |
| let range = element.ownerDocument.createRange() | |
| range.selectNodeContents(element) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Parse a filesize to its number of bytes | |
| * | |
| * @param string|int|float $input | |
| * @param int $base | |
| * @return int | |
| * | |
| * @see https://github.com/patrickkettner/filesize-parser, the original JavaScript implementation of this function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Convert a bitmask to an array of its individual bits | |
| * | |
| * @param {number} bitmask The bitmask to dissect | |
| * @return {number[]} | |
| * | |
| * @example | |
| * assert.equal(bitmaskToArray(0b101), [0b100, 0b001]) | |
| */ | |
| export function bitmaskToArray(bitmask) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect, useState } from 'react' | |
| /** | |
| * React hook which provides the size of the terminal, based on https://usehooks.com/useWindowSize/ | |
| * Great for usage with Ink (https://npmjs.com/package/ink) | |
| */ | |
| export function useTerminalSize() { | |
| const [terminalSize, setTerminalSize] = useState([ | |
| process.stdout.columns, | |
| process.stdout.rows |
This is a Sass mixin to handle a 3-way dark mode. It relies on a data-theme attribute on your <html> element with a value of light or dark. If data-theme is absent (i.e. it's neither light nor dark), the system's preferred mode is used.
body {
// matches data-theme="light" or data-theme="auto" with system instructing light mode
@include light {
background: white;
color: black;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This userscript redirects you to the English version of a website if it's denoted in the source code. | |
| // Insert any URLs of websites below (after @match), for example https://developer.mozilla.org/* or https://www.php.net/* | |
| // Use multiple @match clauses to enable the script on several domains. | |
| // ==UserScript== | |
| // @name Redirect to English | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.0 | |
| // @description Redirect websites to their English version | |
| // @author Florian Reuschel <[email protected]> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function walk_dom(DOMNode $domNode, callable $callback): void | |
| { | |
| foreach ($domNode->childNodes as $node) { | |
| $callback($node); | |
| if ($node->hasChildNodes()) { | |
| walk_dom($node, $callback); | |
| } |