Skip to content

Instantly share code, notes, and snippets.

View honghaoz's full-sized avatar
:shipit:
shipit

Honghao honghaoz

:shipit:
shipit
View GitHub Profile
@shial4
shial4 / DynamicList.swift
Last active September 11, 2024 05:29
SwiftUI Dynamic horizontal or vertical list - loads only visible elements. Efficiency for large collections. Dynamic item size.
import SwiftUI
import Foundation
import PlaygroundSupport
public enum Orientation {
case horizontal
case vertical
}
public struct StackView<Content: View>: View {
@danielmartin
danielmartin / BetterXcodeJumpToCounterpartSwift.org
Last active March 9, 2024 02:00
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"
@alexpaul
alexpaul / SwiftUIDismissModalView.swift
Last active April 17, 2024 10:22
SwiftUI dismiss modal view presentation
// Works on Xcode 11 GM as of 09/12/19
// Presenting view
// make sure the .sheet modifier is tied to the root View
import SwiftUI
struct ContentView: View {
@State private var showingModalView = false
@steipete
steipete / UIWindow+PSPDFAdditions.h
Last active June 5, 2024 20:09
Mac Catalyst: Get the NSWindow from a UIWindow (Updated for macOS 11 Big Sur, also works with Catalina)
// Don't forget to prefix your category!
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIWindow (PSPDFAdditions)
#if TARGET_OS_UIKITFORMAC
@jeamland
jeamland / playlist_extractor.py
Last active September 14, 2021 21:29
iTunes Library (non-XML) playlist extractor
#!/usr/bin/env python
# Extract playlists from a non-XML iTunes Library file (.itl)
# Copyright (c) 2018 Benno Rice, released under the BSD (2 Clause) Licence.
# Important information on the encryption used in the .itl file found here:
# https://mrexodia.cf/reversing/2014/12/16/iTunes-Library-Format-1
# Highly useful information on the .itl format itself found here:
# https://github.com/josephw/titl/blob/master/titl-core/src/main/java/org/kafsemo/titl/ParseLibrary.java
@tclementdev
tclementdev / libdispatch-efficiency-tips.md
Last active November 15, 2024 01:56
Making efficient use of the libdispatch (GCD)

libdispatch efficiency tips

The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).

My take-aways are:

  • You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.

  • Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse

import Foundation
import MobileCoreServices
struct UTType: CustomStringConvertible {
let value: CFString
init?(mimeType: String) {
guard let UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, mimeType as CFString, nil)?.takeUnretainedValue() else { return nil }
value = UTI
}
@jessesquires
jessesquires / gitsl.sh
Last active August 9, 2024 13:43
git "smartlog" / "pretty log"
# blog post
#
# https://www.jessesquires.com/blog/customizing-git-log/
git log --graph --pretty=format:'commit: %C(bold red)%h%Creset %C(red)<%H>%Creset %C(bold magenta)%d %Creset%ndate: %C(bold yellow)%cd %Creset%C(yellow)%cr%Creset%nauthor: %C(bold blue)%an%Creset %C(blue)<%ae>%Creset%n%C(cyan)%s%n%Creset'
@zwaldowski
zwaldowski / A-Swift-UTI.swift
Last active May 9, 2019 01:30
MobileCoreServices Swift audit
let swift = UTType.swiftSource
print(swift) // => Swift Source Code
print(swift.rawValue) // public.swift-source
print(swift.conforms(to: .sourceCode)) // => true
print(swift.declaration?[.conformsTo] as Any) // [ "public.source-code" ]
print(swift.declaringBundleURL as Any) // => /System/Library/CoreServices/MobileCoreTypes.bundle
print(swift.isDeclared) // => true
print(swift.isDynamic) // => false
print(swift.preferredTag(for: .filenameExtension) as Any) // => "swift"
print(UTType(preferredTag: "swift", for: .filenameExtension, conformingTo: nil) == swift) // => "true"
@mrlesmithjr
mrlesmithjr / ansible-macos-homebrew-packages.yml
Last active October 29, 2024 13:33
Install MacOS Homebrew Packages With Ansible
---
- name: Install MacOS Packages
hosts: localhost
become: false
vars:
brew_cask_packages:
- atom
- docker
- dropbox
- firefox