This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://medium.com/ancestry-product-and-technology/swiftui-pro-tips-preferencekey-360505ff8fbb | |
import SwiftUI | |
struct TotalWidth { | |
struct Key: PreferenceKey { | |
static var defaultValue: CGFloat = 0.0 | |
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { | |
value = max(value, nextValue()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the dimensions of each square | |
image_width, image_height = image.size | |
num_squares = 6 # 6x6 grid | |
square_width = image_width // num_squares | |
square_height = image_height // num_squares | |
# Function to calculate average color of a region | |
def average_color(region): | |
return np.mean(region.reshape(-1, 3), axis=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from https://nonstrict.eu/blog/2023/stretching-an-audio-file-using-swift/ | |
import Foundation | |
import AVFoundation | |
func scaleAudio(inputURL: URL, toDuration targetDuration: CMTime, outputURL: URL) async throws { | |
// Load info from the input audio file | |
let inputAudioAsset = AVAsset(url: inputURL) | |
let inputAudioDuration = await inputAudioAsset.load(.duration) | |
let inputAudioTimeRange = CMTimeRange(start: .zero, duration: inputAudioDuration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put the following code into a new VisionOS 2 beta project and run it | |
// inside a real device (hand tracking will fail in the simulator) | |
// interacting with the door on the hinge will separate it from the hinge | |
import SwiftUI | |
import RealityKit | |
import ARKit | |
let mat1 = UnlitMaterial(color: .blue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SixLabors.ImageSharp; | |
using SixLabors.ImageSharp.Processing; | |
using SixLabors.ImageSharp.PixelFormats; | |
using Image = SixLabors.ImageSharp.Image; | |
using SixLabors.ImageSharp.Formats.Png; | |
class Program | |
{ | |
static readonly PngEncoder encoder = new() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static readonly StringBuilder buffer = new StringBuilder(); | |
void Main() | |
{ | |
// first mod adds transpiler | |
Console.WriteLine("// APPLYING PATCH 1"); | |
var h1 = new Harmony("test1"); | |
h1.CreateClassProcessor(typeof(Patch1)).Patch(); | |
// second mod adds transpiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
Test.Run(); | |
var harmony = new Harmony("test"); | |
harmony.PatchCategory("category1"); | |
Test.Run(); | |
harmony.PatchCategory("category2"); | |
Test.Run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var harmony = new Harmony("test"); | |
Harmony.DEBUG = true; | |
harmony.PatchAll(); | |
Class.Test(); | |
} | |
[HarmonyPriority(Priority.High)] | |
[HarmonyPatch(typeof(Class), nameof(Class.Test))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
var test = new Test(); | |
Console.WriteLine($"--> OriginalMethod={test.OriginalMethod(0, "foobartest")}"); | |
Console.WriteLine(""); | |
Console.WriteLine($"--> OriginalMethod={test.OriginalMethod(123, "foobartest")}"); | |
Console.WriteLine(""); | |
// patching would happen here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The following code creates this class: | |
using System; | |
public static void Method1() | |
{ | |
try | |
{ | |
Console.WriteLine("code"); | |
} |
NewerOlder