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
@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
@sbailliez
sbailliez / vagrant-vmware-fusion-13-apple-m1-pro.md
Last active June 25, 2024 13:33
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() {
@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 {
@joevt
joevt / ioreg.pl
Last active March 10, 2024 08:39
perl script parses ioreg output, can output JSON, dumps M1 Mac display timings.
#!/bin/perl
# by joevt Nov 18, 2021
use 5.010;
use strict;
#use warnings;
use Data::Dumper qw(Dumper);
use JSON::PP;