In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literal
interface ExtraOpts { | |
class?: string | string[]; | |
data?: Record<string, string>; | |
} | |
type TagName = keyof HTMLElementTagNameMap; | |
type Tag = HTMLElementTagNameMap; | |
type Opts<K extends TagName> = Partial<Tag[K]> & ExtraOpts; | |
type Child = Node | string; |
/* | |
# `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. |
// Types for the result object with discriminated union | |
type Success<T> = { | |
data: T; | |
error: null; | |
}; | |
type Failure<E> = { | |
data: null; | |
error: E; | |
}; |
type NextDigit = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
type Split<Str> = Str extends `${infer Head extends number}${infer Tail}` ? [Head, ...Split<Tail>] : [] | |
type Increase<X extends number[]> = X extends [...infer Rest extends number[], infer Last extends number] ? | |
Last extends 9 ? [...Increase<Rest>, 0] : [...Rest, NextDigit[Last]] | |
: [1] | |
type TupleToString<T extends number[]> = | |
T extends [infer First extends number, ...infer Rest extends number[]] |
In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literal
import {ChevronLeft, ChevronRight} from 'lucide-react'; | |
import {useEffect, useState} from 'react'; | |
export function Pagination({carousel}: {carousel: HTMLElement}) { | |
// Scroll by 1 page in the given direction (-1 or +1). | |
// This uses the width of the carousel minus the padding and gap between items. | |
// Use behavior: 'smooth' and the browser will animate the scrolling. | |
let scroll = (dir: number) => { | |
let style = window.getComputedStyle(carousel); | |
carousel.scrollBy({ |
#! /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 |
/*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 |
#!/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 |