Skip to content

Instantly share code, notes, and snippets.

View krzyzanowskim's full-sized avatar

Marcin Krzyzanowski krzyzanowskim

View GitHub Profile
@krzyzanowskim
krzyzanowskim / .gitconfig
Last active February 4, 2025 21:45
commit-ai
[alias]
# need llm CLI: https://llm.datasette.io/en/stable/
# based on https://gist.github.com/karpathy/1dd0294ef9567971c1e4348a90d69285?permalink_comment_id=5167582#gistcomment-5167582
commit-ai = "!f() { if [ -n \"$(git diff --cached)\" ]; then git commit -m \"$(git diff --cached | llm -m '4o-mini' 'Below is a diff of all staged changes, coming from the command:\\n```\\ngit diff --cached\\n```\\nPlease generate a concise, two-sentence, maximum 100 characteres commit message for these changes. Do not mention project name.')\"; else echo 'No changes to commit'; fi }; f"
@krzyzanowskim
krzyzanowskim / FB16105564.md
Created December 15, 2024 21:52
FB16105564: NSTextFinder no longer call -showFindBarView: (regression)

NSTextFinder documentation for the findBarContainer property says:

When the find bar is to be shown, NSTextFinder invokes showFindBarView: on the findBarContainer object, passing the view for the find bar, which it should display somewhere that is associated appropriately with the content being searched.

however that method is never ever called. There's little use of that method found on the Internet, and the only instance I found in Mozilla codebase, that suggest that maybe was called in the past. That would mean this is regression bug.

macOS 15.2 (24C101) Xcode 16.2 (16C5032a)

import AsyncAlgorithms
final class AsyncChannelObserverToken {
private let task: Task<Void, Error>
fileprivate init(_ task: Task<Void, Error>) {
self.task = task
}
func cancel() {
if !task.isCancelled {
extension StringProtocol {
subscript(_ offset: Int) -> String.Element {
if offset >= 0 {
self[index(startIndex, offsetBy: offset)]
} else {
self[index(endIndex, offsetBy: offset)]
}
}
@krzyzanowskim
krzyzanowskim / FB15439084.md
Last active November 8, 2024 19:58
FB15439084: NSTextList is Equatable in Swift but not equatable in common sense

NSTextList is Equatable because NSObject is always Equatable, however if anyone expect that may compare two instances of NSTextList that is false. This is because NSTextList.isEqual() do return true value for equal instances. This situation makes impossible to eg. compare NSParagraphStyle instances with testLists property as it will always fail. This situation seems easy fixable and will significanlty improve testability of the codebases (eg. mine)

        do {
            let a = NSTextList(markerFormat: .disc, options: 0) // Equatable
            let b = NSTextList(markerFormat: .disc, options: 0) // Equatable
            let c = a == b        // false
            let co = a.isEqual(b) // false
        }
@krzyzanowskim
krzyzanowskim / .lessfilter
Last active November 8, 2024 14:46
less command with markdown highlighting
#!/bin/sh
# SETUP
#
# create executable file ~/.lessfilter with the content of this file
# chmod u+x ~/.lessfilter
#
# setup less by adding lines below to ~/.zshrc
# ```
# export LESSOPEN="| ~/.lessfilter %s"
@krzyzanowskim
krzyzanowskim / filewrapper.swift
Last active October 22, 2024 23:18
Filewrapper does not reread (refresh) its content
import Foundation
let dirURL = URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test")
// cleanup
try? FileManager.default.removeItem(at: URL(filePath: "/Users/marcinkrzyzanowski/Downloads/filewrappertest.test/COPY.png"))
let fw = try FileWrapper(url: dirURL)
// fw.fileWrappers // ["IMG_0736.png": <NSFileWrapper: 0x6000023a8420>]
@krzyzanowskim
krzyzanowskim / FB14165227.md
Last active October 2, 2024 11:29
FB14165227: UlTextView erroneously overrides string attributes when applying spellchecker annotation attributes

UITextView erroneously overrides string attributes when applying spellchecker annotation attributes.

It doesn't need any particular setting. Default UITextView instance with attributed text

let textView = UITextView(usingTextLayoutManager: true)
textView.spellCheckingType = .yes

Once spellcheck attributes get applied, other attributes like foregroundColor gets applied to the mispelled words. This behavior happens only on Mac Catalyst, and started to appear on macOS 14 or newer.

@krzyzanowskim
krzyzanowskim / enumerateattributes.swift
Last active September 28, 2024 11:27
FB12863947: NSAttributedString.enumerateAttribute called for missing attributes
// Documentation says:
//
// > Executes the specified block for each range of a particular attribute in the attributed string.
//
// documentation is not correct (or implementation, hard to tell). The block is executed at least once, not matter if particular attribute is or is not present in the attributed string.
import Foundation
import AppKit
/// Attributed string without any attribute, in particular no font attribute set
@krzyzanowskim
krzyzanowskim / FB15281730.md
Created September 26, 2024 12:18
FB15281730: UITextInput marked text (IME) methods not called for certain languages on certain devices (or systems)

UITextView does not call its marked text methods (setMarkedText, setAttributedMarkedText) for some languages, and does for other languages, but also for the same language it does not call on iOS, but does call on Catalyst (designed for iPad). Here's the example:

class TestView: UITextView {

    override func setMarkedText(_ markedText: String?, selectedRange: NSRange) {
        super.setMarkedText(markedText, selectedRange: selectedRange) // not called
    }

 override func setAttributedMarkedText(_ markedText: NSAttributedString?, selectedRange: NSRange) {