Skip to content

Instantly share code, notes, and snippets.

@funkenstrahlen
funkenstrahlen / PrintDataAsString.swift
Created March 10, 2021 14:22 — forked from jkereako/PrintDataAsString.swift
LLDB commands to print a Data object as a String. It only works if the underlying data is actually a String.
// See: http://stackoverflow.com/questions/11531353/viewing-nsdata-contents-in-xcode#25097265
po String(data: data, encoding: .utf8)
// Objective-C equivalent.
// See: http://stackoverflow.com/questions/11531353/viewing-nsdata-contents-in-xcode#19626815
// p (char *)[buffer bytes]
@lancethomps
lancethomps / close_notifications_applescript.js
Last active April 8, 2024 07:43
AppleScript to close all notifications on macOS Big Sur, Monterey, and Ventura
function run(input, parameters) {
const appNames = [];
const skipAppNames = [];
const verbose = true;
const scriptName = "close_notifications_applescript";
const CLEAR_ALL_ACTION = "Clear All";
const CLEAR_ALL_ACTION_TOP = "Clear";
@d4rkd3v1l
d4rkd3v1l / ExpansionHandler.swift
Last active January 31, 2024 02:24
SwiftUI: DisclosureGroup "expansion handler" to only have one group expanded at a time, and automatically hiding the last one, when expanding a new one.
class ExpansionHandler<T: Equatable>: ObservableObject {
@Published private (set) var expandedItem: T?
func isExpanded(_ item: T) -> Binding<Bool> {
return Binding(
get: { item == self.expandedItem },
set: { self.expandedItem = $0 == true ? item : nil }
)
}
@funkenstrahlen
funkenstrahlen / Calendar.swift
Created May 8, 2020 07:17 — forked from mecid/Calendar.swift
Calendar view in SwiftUI
import SwiftUI
fileprivate extension DateFormatter {
static var month: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = "MMMM"
return formatter
}
static var monthAndYear: DateFormatter {
@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
//
// UserDefaults+PropertyWrapper.swift
// PodliveShared
//
// Created by Stefan Trauth on 18.06.19.
// Copyright © 2019 Stefan Trauth. All rights reserved.
//
import Foundation
@4np
4np / HowTo use xcconfig or plist with SPM.md
Last active January 25, 2024 22:20
How to use a .xcconfig file and a .plist with a Swift Package Manager based project.

How to use a .xcconfig file and a .plist file with SPM

Worth a read for some more context.

Create a Package.xcconfig file

Create the file in the root of the project (where your Package.swift file lives as well), and use the following contents:

/// Package.xcconfig
@martinpi
martinpi / AutocompleteView.swift
Created November 5, 2018 13:41
An autocomplete popup for text entry. Ported to Swift from this example: https://github.com/danjonweb/NCRAutocompleteTextView
//
// AutocompleteView.swift
//
// Originally created by Daniel Weber on 9/28/14.
// Copyright (c) 2014 Null Creature. All rights reserved.
// Ported to Swift by Martin Pichlmair 2018
//
import Cocoa
@fzwo
fzwo / LegacyDocsets.md
Last active April 11, 2024 09:20
Download and view old Apple developer documentation

How to download and view legacy documentation from Apple (no need to sign in to your dev account)

  1. Download the docset index XML.
  2. Find the docset you want (there are some with URL https://apple.com/none.dmg; ignore them - you will find them again further down the file with a working URL).
  3. Download the dmg. It's probably around a gigabyte or so.
  4. "Install" the .pkg file somewhere on your disk. If you don't trust the installer, do it manually:
    1. Find the largest file, named Payload, and extract it using The Unarchiver.
    2. This creates a new, even larger file, probably named Payload-1.
    3. Extract Payload-1 using The Unarchiver.
  5. After many minutes of extracting, we have our .docset file.

Aligning images

This is a guide for aligning images.

See the full Advanced Markdown doc for more tips and tricks

left alignment