Skip to content

Instantly share code, notes, and snippets.

View xavierLowmiller's full-sized avatar
🌴
I may be slow to respond.

Xaver Lohmüller xavierLowmiller

🌴
I may be slow to respond.
View GitHub Profile
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// https://adventofcode.com/2020/day/23
int lut[1000001];
int current = 0;
void setup(const char *numbers) {
@xavierLowmiller
xavierLowmiller / Shimmer.swift
Last active June 6, 2023 03:50
Slide-to-Unlock animation in SwiftUI
import SwiftUI
public struct Shimmer: AnimatableModifier {
private let gradient: Gradient
@State private var position: CGFloat = 0
public var animatableData: CGFloat {
get { position }
@xavierLowmiller
xavierLowmiller / iOS14AdTracking.swift
Created September 26, 2020 07:21
Experiments using iOS 14's new AppTrackingTransparency framework
import SwiftUI
import AdSupport
import AppTrackingTransparency
struct ContentView: View {
@State private var trackingStatus: String = ""
@State private var idfa: String = ""
func updateIdfa() {
@xavierLowmiller
xavierLowmiller / WatchOS_CounterApp.swift
Created September 2, 2020 18:50
A simple counter app for watchOS
import SwiftUI
@main
struct WatchOS_CounterApp: App {
@AppStorage("counter") var counter = 0
var body: some Scene {
WindowGroup {
VStack {
Text("\(counter)")
// Based on this StackOverflow answer: https://stackoverflow.com/a/61273595/4239752
import Foundation
import Combine
extension Publisher {
/// collects elements from the source sequence until the boundary sequence fires. Then it emits the elements as an array and begins collecting again.
func buffer<T: Publisher, U>(_ boundary: T) -> AnyPublisher<[Output], Failure> where T.Output == U {
let subject = PassthroughSubject<[Output], Failure>()
@xavierLowmiller
xavierLowmiller / DictionaryMerge.swift
Last active January 17, 2018 16:15
Operator sugar for dictionary merge methods
extension Dictionary {
/// Merges two dictionaries.
/// When a key is present in both dictionaries, `lhs`'s keys are overwritten
///
/// - Parameters:
/// - lhs: The base dictionary. Its keys may be overwritten by `rhs`'s keys
/// - rhs: The added dictionary. Its keys may overwrite `lhs`'s keys
static func + (lhs: [Key: Value], rhs: [Key: Value]) -> [Key: Value] {
return lhs.merging(rhs, uniquingKeysWith: { $1 })
@xavierLowmiller
xavierLowmiller / UIGestureRecognizer+Closure.swift
Last active April 27, 2017 21:33
Convenience Initializer for UIGestureRecognizer that takes a closure
import UIKit
import ObjectiveC
private typealias GestureClosure = (UIGestureRecognizer) -> Void
private var handle: UInt8 = 0
extension UIGestureRecognizer {
/**
Initialize a UIGestureRecognizer (or subclass) with a closure