Skip to content

Instantly share code, notes, and snippets.

View jasdev's full-sized avatar

Jasdev Singh jasdev

View GitHub Profile
@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 {
@krzysztofzablocki
krzysztofzablocki / gist:338eddf527a351de825bd62cf2a1de28
Last active June 13, 2024 12:19
Use Sourcery to Generate bash script that will rewrite your source code to add final to all classes that have no inheritance
#!/usr/bin/env bash
<% for type in types.classes { -%>
<%_ if type.modifiers.map{ $0.name }.contains("final") || type.modifiers.map{ $0.name }.contains("open") || types.based[type.name].isEmpty == false { continue } -%>
<%_ _%>git grep -lz 'class <%= type.name %>' | xargs -0 perl -i'' -pE "s/class <%= type.name %>(?=\s|:)/final class <%= type.name %>/g"
<% } %>
// Run with Sourcery on your codebase and then execute generated code via bash :)
@daltonclaybrook
daltonclaybrook / TextAttributes.swift
Created January 15, 2022 19:13
An Equatable, value-semantic container for NSAttributedString attributes
import Foundation
/// An Equatable container for storing and accessing just the attributes of an NSAttributedString without
/// caring about the string itself.
struct TextAttributes: Equatable {
private var storage = NSMutableAttributedString(string: "")
mutating func setAttributes(_ attributes: [NSAttributedString.Key: Any], range: NSRange) {
preserveUniqueReferenceToStorageIfNecessary()
extendStringRangeIfNecessary(range: range)
import Foundation
protocol Placeholding {
static func placeholder() -> Self
}
struct PlaceholderArray<Element: Placeholding>: RandomAccessCollection {
typealias SubSequence = Slice<Self>
var startIndex: Int { indices.lowerBound }
@brennanMKE
brennanMKE / IDETemplateMacros.plist
Last active October 27, 2024 01:19
Xcode File Header Templates
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
// Copyright © ___YEAR___ ___ORGANIZATIONNAME___.
// All Rights Reserved.
</string>
<key>ORGANIZATIONNAME</key>
@IanKeen
IanKeen / FocusState.swift
Last active June 26, 2024 07:34
SwiftUI: FocusedState shim for < iOS15
import Combine
import SwiftUI
extension View {
public func focused<T>(file: StaticString = #file, _ state: FocusState<T>, equals value: T) -> some View {
modifier(FocusedModifier(state: state, id: value, file: file))
}
}
@propertyWrapper
@krzysztofzablocki
krzysztofzablocki / debugDiffing.swift
Created August 18, 2021 18:28
Higher order reducer for TCA that enables better debugging
import ComposableArchitecture
import Difference
import Foundation
/// A container for storing action filters.
///
/// The logic behind having this rather than a normal closure is that it allows us to namespace and gather action filters together in a consistent manner.
/// - Note: You should be adding extensions in your modules and exposing common filters you might want to use to focus your debugging work, e.g.
/// ```swift
/// extension ActionFilter where Action == AppAction {
@cheeaun
cheeaun / ocr.sh
Last active December 6, 2023 20:38
macOCR script for Raycast. Preview https://twitter.com/cheeaun/status/1395973544983425025
#!/bin/bash
# Dependency: requires macOCR
# Download: https://github.com/schappim/macOCR
# @raycast.schemaVersion 1
# @raycast.title macOCR
# @raycast.mode silent
# @raycast.author Lim Chee Aun
# @raycast.authorURL https://github.com/cheeaun
@djds23
djds23 / SKAction+Keypath.swift
Created March 2, 2021 03:41
An SKAction that writes a value to a specified object.
extension SKAction {
static func write<Root: AnyObject, Value>(
value: Value,
to keyPath: ReferenceWritableKeyPath<Root, Value>,
on object: Root
) -> SKAction {
SKAction.customAction(withDuration: 0) { [weak object] _, _ in
object?[keyPath: keyPath] = value
}
@IanKeen
IanKeen / Example.swift
Created February 7, 2021 03:09
PropertyWrapper: Ignore codable properties
struct Foo: Codable {
var name: String
@Ignore var foo: Int?
}
let model = Foo(name: "Ian", foo: 42)
let data = try! JSONEncoder().encode(model)
print(String(data: data, encoding: .utf8)!) // {"name":"Ian"}