Skip to content

Instantly share code, notes, and snippets.

@mjmsmith
mjmsmith / PaddingModifier.swift
Last active December 19, 2024 21:18
Padding modifier for SwiftUI views.
// NOTE: Nil values implicitly or explicitly passed as arguments to padding() are ignored.
// This differs from the built-in SwiftUI version:
//
// view.padding(trailing: nil) // has no effect
// view.padding(.trailing, nil) // resets to default
//
// See below for a version that matches the built-in behavior.
extension View {
func padding(horizontal: CGFloat? = nil, vertical: CGFloat? = nil,
//
// OCXML.swift
// Created by Marco Arment on 9/23/24.
//
// Released into the public domain. Do whatever you'd like with this.
// No guarantees that it'll do anything, or do it correctly. Good luck!
//
import Foundation
@will
will / favs.sh
Last active September 26, 2024 07:07
apple photos favorites
# copy database to avoid locks and messing up real database
$ cd /tmp
$ cp ~/Pictures/Photos\ Library.photoslibrary/database/Photos.sqlite photosdbcopy
# get favorites
$ sqlite3 photosdbcopy 'select a.ZUUID, cm.ZORIGINALFILENAME from ZASSET a JOIN ZCLOUDMASTER cm ON a.ZMASTER = cm.Z_PK where a.ZFAVORITE=1 limit 10;'
E34F59CF-332D-40EB-80B2-48EDD30D5122|IMG_0125.JPG
BFDEF572-1E73-4187-99CD-F3B22A8A0349|IMG_0444.JPG
21D1788D-D0A0-4C03-BD8E-BE32B11C179D|IMG_0490.JPG
12755BB5-C836-4ED0-8915-2E0BE685E9B4|IMG_0521.JPG
//
// ColorSchemeApp.swift
// ColorScheme
//
// Created by Craig Hockenberry on 9/11/24.
//
import SwiftUI
@main
@siracusa
siracusa / observer.swift
Last active June 17, 2024 16:47
Swift Concurrency Candidate
NSWorkspace.shared.notificationCenter.addObserver(
forName: NSWorkspace.didLaunchApplicationNotification,
object: nil, queue: nil, using: { [weak self] notification in
self?.doStuff()
})
@macshome
macshome / EnvironmentVariables.swift
Created May 2, 2024 12:48
A playground to see different ways to get environment variables in Swift
import Foundation
// A playground to see different ways to get environment variables in Swift
// Foundation is the easiest way using the awesome ProcessInfo class.
// Get all of the environment variables for your running process in a Dictionary.
let foundationEnv = ProcessInfo().environment
print("********** ProcessInfo Environment **********")
@chockenberry
chockenberry / ContentView.swift
Created April 12, 2024 17:58
Optional Bindable
//
// ContentView.swift
// BindableOptional
//
// Created by Craig Hockenberry on 4/12/24.
//
import SwiftUI
@Observable
@thesamesam
thesamesam / xz-backdoor.md
Last active February 26, 2025 01:17
xz-utils backdoor situation (CVE-2024-3094)

FAQ on the xz-utils backdoor (CVE-2024-3094)

This is a living document. Everything in this document is made in good faith of being accurate, but like I just said; we don't yet know everything about what's going on.

Update: I've disabled comments as of 2025-01-26 to avoid everyone having notifications for something a year on if someone wants to suggest a correction. Folks are free to email to suggest corrections still, of course.

Background

@OrionReed
OrionReed / dom3d.js
Last active February 17, 2025 22:17
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@stephancasas
stephancasas / NSApplication+NSResponderDebug.swift
Created March 18, 2024 20:35
An extension on NSApplication providing a computed property that describes the current responder chain.
//
// NSApplication+NSResponderDebug.swift
//
// Created by Stephan Casas on 3/18/24.
//
import Cocoa;
extension NSApplication {