Skip to content

Instantly share code, notes, and snippets.

View danielbayley's full-sized avatar
👨‍💻
Working on too many things…

Daniel Bayley danielbayley

👨‍💻
Working on too many things…
View GitHub Profile
@kwikwag
kwikwag / node-engine-strict.js
Created April 29, 2025 09:31
A script that ensures your project runs with a Node.js version that satisfies the `engines.node` field in your `package.json`, using either NVM or the system-installed Node.js.
/*
# `node-engine-strict.js`
A script that ensures your project runs with a Node.js version that satisfies
the `engines.node` field in your `package.json`.
It works by checking for a compatible version installed via **NVM** (Node
Version Manager), and will fall back to the system-installed Node.js if it's
compatible. If neither is suitable, the script exits with an error.
@t3dotgg
t3dotgg / try-catch.ts
Last active April 29, 2025 18:59
Theo's preferred way of handling try/catch in TypeScript
// Types for the result object with discriminated union
type Success<T> = {
data: T;
error: null;
};
type Failure<E> = {
data: null;
error: E;
};

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@danielbayley
danielbayley / seticon.swift
Created February 25, 2023 15:27
Set icon for file or folder from image, existing app or folder.
#! /usr/bin/xcrun swift
import Cocoa
let args = CommandLine.arguments[1...]
let (target, icon) = (URL(fileURLWithPath: args.first!).path, args[2])
var folder: ObjCBool = false
FileManager.default.fileExists(atPath: icon, isDirectory: &folder)
let image: NSImage = folder.boolValue
@kaizhu256
kaizhu256 / globExclude.mjs
Last active June 29, 2024 01:21
This gist file demos a performant, self-contained function "globExclude()", which batch-globs <pathnameList> in a single pass, with given filters <excludeList>, <includeList>.
/*jslint beta, node*/
// This gist file demos a performant, self-contained function "globExclude()",
// which batch-globs <pathnameList> in a single pass,
// with given filters <excludeList>, <includeList>.
//
// Could be useful if you need to glob thousands of files for test-coverage,
// or other purposes.
// Example usage
@n8henrie
n8henrie / OpenTerminalToFinderWindow.js
Last active March 9, 2025 02:19
JXA to open a Terminal window to the frontmost Finder window
#!/usr/bin/osascript -l JavaScript
'use strict';
const DEBUG = false;
function launchTerminal(path) {
const terminalApp = Application("Terminal.app")
terminalApp.includeStandardAdditions = true
let cmd = `cd ${path}; clear;`
url scheme:
x-apple.systempreferences:com.apple.KEY[.KEY]?SUB-PANE
examples:
x-apple.systempreferences:com.apple.systempreferences.AppleIDSettings?iCloud
x-apple.systempreferences:com.apple.preference.keyboard?Shortcuts
urls:
com.apple.systempreferences.ApplelDSettings
@raven
raven / fetch-xcode.sh
Created September 23, 2022 12:24
Download Xcode without Apple ID
# Fetch ADCDownloadAuth cookie
curl --cookie-jar cookie_file 'https://developerservices2.apple.com/services/download?path=%2FDeveloper_Tools%2FXcode_14%2FXcode_14.xip'
# Download Xcode using fetched ADCDownloadAuth cookie
curl --cookie cookie_file --remote-name 'https://download.developer.apple.com/Developer_Tools/Xcode_14/Xcode_14.xip'
@monkeydom
monkeydom / ks_changeset.sh
Created May 3, 2022 08:13
Script to put 2 folders into a single changeset git and diff it using ksdiff to see the changeset nicely
#!/bin/sh
# ks_changeset v0.9 - 2022-05-03
# Enable "safe" mode - see http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
if [[ $# -lt 3 ]]; then
echo "Usage: ks_changeset.sh <FolderA> <FolderB> <DestinationGit>"