Skip to content

Instantly share code, notes, and snippets.

View dreymonde's full-sized avatar
🇺🇦

Oleg Dreyman dreymonde

🇺🇦
View GitHub Profile
@lukepistrol
lukepistrol / TaskTrigger.swift
Last active November 19, 2023 19:32
Attach async tasks to SwiftUI views using a trigger mechanism.
import SwiftUI
struct TaskTrigger<T: Equatable>: Equatable {
fileprivate enum TaskState<S: Equatable>: Equatable {
case inactive
case active(value: S, uniqueId: UUID? = nil)
}
fileprivate var state: TaskState<T> = .inactive
@jordansinger
jordansinger / Settings.swift
Created February 20, 2021 18:30
iOS 6 Settings built in SwiftUI
//
// Settings.swift
// Settings
//
// Created by Jordan Singer on 2/20/21.
//
import SwiftUI
struct Settings: View {
@DougGregor
DougGregor / parallel_map.swift
Created December 24, 2020 01:10
Swift async/await implementation of a parallel map
extension Collection {
func parallelMap<T>(
parallelism requestedParallelism: Int? = nil,
_ transform: @escaping (Element) async throws -> T
) async throws -> [T] {
let defaultParallelism = 2
let parallelism = requestedParallelism ?? defaultParallelism
let n = self.count
if n == 0 {
@Luoyayu
Luoyayu / gist:3c5f099dd1a453f049fced1df7bc7964
Created December 12, 2019 18:48
extract Xcode.xip to a customed volume
By default, when extracts the Xcode.zip,
macos will create tmp file in `/private/var/folders/v2/tbmrn60d2910x3w23ys5fgs00000gn/T/com.apple.AUHelperService`.
Sometimes, the /private has no ehough space to hold 19GB Xcode.app.
Thus we can create a soft link named `com.apple.AUHelperService` in the tmp dir.
Steps:
1. BACKUP `com.apple.AUHelperService` in `/private/var/folders/v2/tbmrn60d2910x3w23ys5fgs00000gn/T/` to `com.apple.AUHelperService_BACKUP`
2. mkdir named `com.apple.AUHelperService` wherever you have enough space,
3. ln -s /your/absolute/path/com.apple.AUHelperService /private/var/folders/v2/tbmrn60d2910x3w23ys5fgs00000gn/T
4. double click the Xcode.xip
@floriankugler
floriankugler / AutoLayoutHelpers.swift
Last active August 30, 2023 21:17
Very simple key path based Auto Layout helpers
import UIKit
typealias Constraint = (UIView, UIView) -> NSLayoutConstraint
func equal<L, Axis>(_ to: KeyPath<UIView, L>, constant: CGFloat = 0) -> Constraint where L: NSLayoutAnchor<Axis> {
return equal(to, to, constant: constant)
}
func equal<L, Axis>(_ from: KeyPath<UIView, L>, _ to: KeyPath<UIView, L>, constant: CGFloat = 0) -> Constraint where L: NSLayoutAnchor<Axis> {
return { view1, view2 in
@gcbrueckmann
gcbrueckmann / JSONValue.swift
Last active January 22, 2023 14:46
Decode arbitrary JSON values using Swift.Decodable
import Foundation
/// Wrapper allowing decoding of arbitrary JSON values,
/// i. e. values whose specific type is not known at compile time.
///
/// This is a workaround for Swift 4’s decoding system not allowing
/// something like `JSONDecoder().decode([String: Any], forKey: .foo)`,
/// because `Any` does not (and cannot) conform to `Decodable`.
///
/// Access the underlying value using the `anyValue` property.
@JeOam
JeOam / Animation.md
Last active February 18, 2024 21:18
iOS Core Animation: Advanced Techniques, Part 1: The Layer Beneath

Author: https://www.cyanhall.com/

1. The Layer Tree

Core Animation's original name is Layer Kit

Core Animation is a compositing engine; its job is to compose different pieces of visual content on the screen, and to do so as fast as possible. The content in question is divided into individual layers stored in a hierarchy known as the layer tree. This tree forms the underpinning for all of UIKit, and for everything that you see on the screen in an iOS application.

In UIView, tasks such as rendering, layout and animation are all managed by a Core Animation class called CALayer. The only major feature of UIView that isn’t handled by CALayer is user interaction.

There are four hierarchies, each performing a different role:

@jasperf
jasperf / wget-download-site.sh
Last active April 20, 2024 04:42
Use wget to get a local copy of a site with all files and folders . This an ideal way to clone a (static html/css/javascript based ) site from the command line. #copy #clone #wget #download
#http://stackoverflow.com/questions/6348289/download-a-working-local-copy-of-a-webpage
#http://stackoverflow.com/questions/8755229/how-to-download-all-file-from-website-using-wget
#http://stackoverflow.com/questions/4272770/wget-with-authentication?rq=1
#add browser headers:
#--header="Accept: text/html" --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/30.0"
#add .htaccess authentication details:
#--password=password --user=user
wget -m -p -E -k -K -np http://site/path/
wget -p -k http://ExampleSite.com
# and another via Quora https://www.quora.com/How-do-you-export-a-WordPress-site-to-a-static-HTML
@jacobbubu
jacobbubu / ioslocaleidentifiers.csv
Created February 15, 2012 14:41
iOS Locale Identifiers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)