Skip to content

Instantly share code, notes, and snippets.

View michaelevensen's full-sized avatar

Michael Nino Evensen michaelevensen

View GitHub Profile
@michaelevensen
michaelevensen / Calendar.swift
Created November 12, 2022 09:43 — forked from mecid/Calendar.swift
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
@michaelevensen
michaelevensen / RoundedPolygon.swift
Created October 19, 2022 16:45 — forked from dejager/RoundedPolygon.swift
A SwiftUI Shape that draws a polygon with a given number of corners and a corner radius.
//
// RoundedPolygon.swift
//
// Created by Nate on 2022-10-17.
//
import SwiftUI
struct RoundedPolygon: Shape {
func fetchData() async
throws {
guard let url = URL(string: urlString) else { return }
let (data, response) = try await URLSession.shared.data(for: URLRequest(url: url))
guard (response as? HTTPURLResponse)?.statusCode == 200 else { throw FetchError.badRequest }
Task { @MainActor in
imageData = try JSONDecoder().decode(PandaCollection.self, from: data)
}
@michaelevensen
michaelevensen / ResizableImage.swift
Created October 11, 2022 08:06
Great way to size a `SwiftUI` image.
Image(image)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(height: 500)
.frame(minWidth: 0, maxWidth: .infinity)
.clipped()
class ResumableTimer: NSObject {
private var timer: Timer? = Timer()
private var callback: () -> Void
private var startTime: TimeInterval?
private var elapsedTime: TimeInterval?
// MARK: Init
private struct ScrollOffsetPreferenceKey: PreferenceKey {
static var defaultValue: CGPoint = .zero
static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {}
}
struct TrackableScrollView<Content: View>: View {
let axes: Axis.Set
let showsIndicators: Bool
let offsetChanged: (CGPoint) -> Void
@michaelevensen
michaelevensen / String+LoremIpsum.swift
Last active September 6, 2022 09:03
Simple function to return a specified amount of `Lorem Ipsum` sentences.
extension String {
static func loremIpsum(numberOfSentences sentenceCount: Int = 1) -> String {
let str: String = """
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam sit amet placerat ante. Proin purus justo, dignissim a elementum eu, gravida vitae nunc. Duis eu tincidunt elit. Cras rhoncus tellus mi, et tempor erat facilisis dignissim. Duis rutrum vel leo nec dignissim. Donec sollicitudin, nisl vel accumsan tincidunt, urna ligula tristique leo, molestie aliquam orci massa at metus. Etiam facilisis leo lacinia orci tempor, ac vehicula libero pulvinar. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi ligula magna, tempus ullamcorper magna in, mollis sodales elit. Nunc ornare suscipit quam, quis tempus dolor semper in.
Morbi dignissim mauris fringilla arcu pharetra pulvinar. Cras orci orci, convallis tincidunt fermentum vel, semper aliquet sapien. Maecenas ipsum nulla, aliquam vel nisl et, porttitor luctus felis. Aliqua
Warning: file_get_contents(http://127.0.0.1:8000//loboApiCurl.php?action=getProductList): failed to open stream: HTTP request failed! in /Users/michaelevensen/Downloads/v1/examplePhp.php on line 30
Abfrage per json(_decode)
Warning: count(): Parameter must be an array or an object that implements Countable in /Users/michaelevensen/Downloads/v1/examplePhp.php on line 36
Anzahl der verfügbaren Produkte: 0
Warning: file_get_contents(http://127.0.0.1:8000//loboApiCurl.php?action=getProductList&responseFormat=base64_serialized): failed to open stream: HTTP request failed! in /Users/michaelevensen/Downloads/v1/examplePhp.php on line 51
Abfrage per unserialize
@michaelevensen
michaelevensen / View+Geometry.swift
Last active November 13, 2023 12:20
A really handy extension to `View` which enables dynamic binding of `GeometryReader` properties like `Size`, `Frame` and `SafeAreaInsets` for a `View`. This is particularly handy when you want to share `GeometryReader` output between other `View`'s. All credit goes to @danielsaidi.
//
// View+Geometry.swift
// SwiftUIKit
//
// Created by Daniel Saidi on 2020-03-26.
// Copyright © 2020 Daniel Saidi. All rights reserved.
//
import SwiftUI
@michaelevensen
michaelevensen / Date+StartEnd.swift
Last active March 4, 2020 19:48
Awesome Date extension.
extension Date {
var startOfDay: Date {
return Calendar.current.startOfDay(for: self)
}
var endOfDay: Date {
var components = DateComponents()
components.day = 1
components.second = -1
return Calendar.current.date(byAdding: components, to: startOfDay)!