Skip to content

Instantly share code, notes, and snippets.

View nylki's full-sized avatar

Tom Brewe nylki

View GitHub Profile
@ryanlintott
ryanlintott / OnPreferenceChangeError.md
Last active April 16, 2025 07:01
FB15989990 - A Sendable onPreferenceChange closure cannot change main actor view properties in Xcode 16.2 beta 3. This has been fixed in Xcode 16.3.

In XCode 16.2 beta 3 the onPreferenceChange view modifier closure was changed to be @Sendable. This change caused a number of errors in my code when I try to use the value in the closure to update a view property.

I’ve attached a simple WidthReader example that shows these errors.

This change seems similar to the recent change to the alignmentGuide closure. The difference is the alignmentGuide closure is used to change the value of the alignment guide and I have no expectation of using it to update view properties. The onPreferenceChange closure returns no value and as far as I can figure the only use of it would be to modify view properties.

As a workaround I could wrap each modification in a main actor Task but I’m concerned about this somehow delaying my updates and causing visual glitches in the UI.

Ideally I would like the onPreferenceChange modifier to be annotated with @MainActor instead of @Sendable as I can’t see a use case when someone would use the value to update something off the main thread.

@drewolbrich
drewolbrich / View+WindowGeometryPreferences.swift
Last active February 8, 2025 15:48
A visionOS SwiftUI view modifier that can be used to hide a window's resize handles or to constrain a window's aspect ratio
//
// View+WindowGeometryPreferences.swift
//
// Created by Drew Olbrich on 1/30/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@wata
wata / ISOString.swift
Last active March 28, 2023 14:46
A simple ISO string parsing and converting library for Swift
public struct ISOString {
/// Parse ISO 6709 string.
/// e.g. "+34.0595-118.4460+091.541/"
/// SeeAlso: [ISO 6709](https://en.wikipedia.org/wiki/ISO_6709)
public static func parse(iso6709 text: String?) -> CLLocation? {
guard
let results = text?.capture(pattern: "([+-][0-9.]+)([+-][0-9.]+)"),
let latitude = results[safe: 1] as NSString?,
let longitude = results[safe: 2] as NSString?
else { return nil }
from math import *
# a performant solution would store a prefix sum of line lengths to
# a sidechannel and then use that to do a bsearch; on the GPU,
# you'd do a sum tree / histopyramid as a preprocessing step
def find_point(points, d):
d = d
for i in range(1, len(points)):
x0,y0 = points[i-1]
x1,y1 = points[i]
@ljaraque
ljaraque / tensorflow-gpu-ubuntu.md
Last active March 12, 2022 10:32
Install tensorflow-gpu in ubuntu

Install tensorflow-gpu1.8 in ubuntu18.04 with CUDA9.2, cuDNN7.2.1 and NVIDIA Driver 396

[email protected]

Overview

This is a summary of the process I lived in order to enable my system with CUDA9.2, cuDNN7.2.1, Tensorflow1.8 and NVIDIA GEFORCE GTX860M GPU. You can just skip the steps marked with FAILED. I decided to keep them there in order to be useful for others who tried those paths too.

FAILED (Next section is successfull) Install NVIDIA driver (FAILED, THIS WILL INSTALL DRIVER 390 which is not compatible with CUDA9.2):

ubuntu-drivers devices
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@DenTelezhkin
DenTelezhkin / MeasureAppStartupTime.swift
Last active May 21, 2024 13:40
Measure iOS app startup time, in seconds, from the time user tapped an icon on the home screen (using time, when app process was created). Swift 4.
// Returns number of seconds passed between time when process was created and function was called
func measureAppStartUpTime() -> Double {
var kinfo = kinfo_proc()
var size = MemoryLayout<kinfo_proc>.stride
var mib : [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]
sysctl(&mib, u_int(mib.count), &kinfo, &size, nil, 0)
let start_time = kinfo.kp_proc.p_starttime
var time : timeval = timeval(tv_sec: 0, tv_usec: 0)
gettimeofday(&time, nil)
let currentTimeMilliseconds = Double(Int64(time.tv_sec) * 1000) + Double(time.tv_usec) / 1000.0
@neingeist
neingeist / zornis pasta al limone[pasta italian via:zornem lemon vegetarian 4star].markdown
Created December 12, 2017 18:30
zornis pasta al limone[pasta italian via:zornem lemon vegetarian 4star].md

zutaten

  • 500g trockene pasta
  • 2-3 zitronen
  • olivenöl
  • pecorino oder parmesan
  • salz, pfeffer

optional:

  • petersilie
@neingeist
neingeist / rosenkohl-in-erdnusssoße.markdown
Last active December 12, 2017 18:58
rosenkohl in erdnusssoße
  • 1 netz rosenkohl
  • 1 zwiebel
  • etwas gemüsebrühe
  • (nicht probiert: zucker)
  • pfeffer

für die soße:

  • 3el erdnussbutter
  • 1-2el sojasoße
@jsantell
jsantell / web-ar-projects.md
Last active June 29, 2019 03:01
Projects for WebARonARKit and WebARonARCore

Projects for WebARonARKit and WebARonARCore

New Projects

Leave a comment to add a project you've created or found!

Browsers