Skip to content

Instantly share code, notes, and snippets.

View MainasuK's full-sized avatar

CMK MainasuK

View GitHub Profile
struct OverflowLayout: Layout {
var spacing = CGFloat(10)
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let containerWidth = proposal.replacingUnspecifiedDimensions().width
let sizes = subviews.map { $0.sizeThatFits(.unspecified) }
return layout(sizes: sizes, containerWidth: containerWidth).size
}
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
@klein-artur
klein-artur / Selectables.swift
Created July 8, 2023 00:13
SwiftUI Selectable List
struct Selectables<Data, ID: Hashable, Content>: View where Content: View {
let data: [Data]
@Binding var selectedIds: [ID]
let id: KeyPath<Data, ID>
let content: (Data, Binding<Bool>) -> Content
init(_ data: [Data], selectedIds: Binding<[ID]>, id: KeyPath<Data, ID>, @ViewBuilder content: @escaping (Data, Binding<Bool>) -> Content) {
self.data = data
self._selectedIds = selectedIds
self.id = id
@ScamCast
ScamCast / gist:2e40befbd1b61c4a80cda2745d4df1f4
Created July 4, 2023 09:34
Twitter Android API Endpoints
/graphql/30bHSx-YYMzaygsBwfhftA/AddRemoveUserFromList
/graphql/xIZJPQBK0Zz62_BDLNLHKw/AddSuperFollowPrivacy
/graphql/R1ks8NLVisD-416R3mAk_w/AllSubscribedListsTimeline
/graphql/nxtTgq_TxeEDm0gmsGqK_Q/ArticleTweetsTimeline
/graphql/zacmhLyVLzFAKvH-yia8OA/AudiospaceAddSharing
/graphql/IZ1drq74xph2Gym7gGgtRw/AudiospaceBrowseSpaceTopicsQuery
/graphql/N80MQ7fkrpuq1-kCWVSvzQ/AudiospaceByRestId
/graphql/PTAe3LYPhlCcPJtwpyyx-w/AudiospaceDeleteSharing
/graphql/NiYfwFZDe-90MSqpGEI16w/AudiospaceGiveawayTickets
/graphql/g1mB1D5y3z_NkFsN-FwZdA/AudiospaceIsSubscribedQuery
@Berhtulf
Berhtulf / ci_post_xcodebuild.sh
Last active November 13, 2024 19:08
Xcode Cloud - CI/CD Push tag to Github
# 1. Create 'ci_scripts' folder in your main project directory
# 2. Create 'ci_post_xcodebuild.sh' inside of it
# 3. Make it an executable by running 'chmod +x $ci_post_xcodebuild.sh'
set -e # fails build if any command fails
if [ ${CI_XCODEBUILD_EXIT_CODE} != 0 ]
then
exit 1
fi
@ohaiibuzzle
ohaiibuzzle / tof_pc_login.sh
Last active May 23, 2024 05:37
Script to login to ToF on PlayCover
# Script to login to ToF on PlayCover
# Select the ToF version
echo "Please select the region of ToF you want to login to:"
echo "[1] Global"
echo "[2] China"
read -p "Enter your choice: " choice
if [ $choice -eq 1 ]; then
import UIKit
import PlaygroundSupport
import Foundation
PlaygroundPage.current.needsIndefiniteExecution = true
//URLSessionTaskDelegate
//You use this protocol in one of two ways, depending on how you use a URLSession:
//If you create tasks with Swift’s async-await syntax, using methods like bytes(for:delegate:) and data(for:delegate:), you pass a delegate argument of this type. The delegate receives callbacks for things like task progress, while the call point awaits the completion of the task. A delegate that receives life cycle and authentication challenge callbacks as the transfer progresses.
//If you add tasks to the session with methods like dataTask(with:) and downloadTask(with:), then you implement this protocol’s methods in a delegate you set on the session. This session delegate may also implement other protocols as appropriate, like URLSessionDownloadDelegate and URLSessionDataDelegate. You can also assign a delegate of this type directly to the task to intercept callbacks before the task deliver
@sbailliez
sbailliez / vagrant-vmware-fusion-13-apple-m1-pro.md
Last active September 28, 2024 13:31
Vagrant and VMWare Fusion 13 on Apple M1 Pro

Vagrant and VMWare Fusion 13 Player on Apple M1 Pro

This document summarizes notes taken to make VMWare Fusion 13 Player work on Apple M1 Pro. It builds upon a previous (deprecated) document based on VMWare Tech Preview 21H1

VMWare Fusion 13 was released on November 17, 2022 and Fusion 13.5 on October 19, 2023

Created on: November 20, 2022

Updated on: June 1, 2024

@buahaha
buahaha / MetalView.swift
Last active November 10, 2023 13:28
Metal API SwiftUI view
//
// Created by Szymon Błaszczyński on 26/08/2021.
//
import Foundation
import MetalKit
import SwiftUI
struct MetalView: NSViewRepresentable {
func makeCoordinator() -> Coordinator {
@helje5
helje5 / main.swift
Last active January 12, 2022 18:44
Using async/await concurrency on iOS 14 and before
// Created by Helge Heß 2021-06-17
import Foundation
// They use obfuscated names to hide it from us!
import JavaScriptCore
/// Setup our async/await runtime.
let runtime = JSContext()!
@DougGregor
DougGregor / initiating-async-work.md
Created April 26, 2021 20:26
Initiating async work from synchronous code

Initiating async work from synchronous code

Motivation

Swift async functions can only directly be called from other async functions. In synchronous code, the only mechanism provided by the Swift Concurrency model to create asynchronous work is detach. The detach operation creates a new, detached task that is completely independent of the code that initiated the detach: the closure executes concurrently, is independent of any actor unless it explicitly opts into an actor, and does not inherit certain information (such as priority).

Detached tasks are important and have their place, but they don't map well to cases where the natural "flow" of control is from the synchronous function into async code, e.g., when reacting to an event triggered in a UI:

@MainActor func saveResults() {