Skip to content

Instantly share code, notes, and snippets.

Avatar

Oliver Drobnik odrobnik

View GitHub Profile
View simpler.swift
func unitSquareIntersectionPoint(_ angle: Angle) -> UnitPoint {
let normalizedDegree = angle.degrees.truncatingRemainder(dividingBy: 360)
let degreeProportion = (normalizedDegree / 90).truncatingRemainder(dividingBy: 4)
switch degreeProportion {
case 0: return UnitPoint(x: 1.0, y: 1.0)
case 1: return UnitPoint(x: 1.0, y: 1.0 - (normalizedDegree - 270) / 90)
case 2: return UnitPoint(x: 1.0 - (normalizedDegree - 180) / 90, y: 0.0)
case 3: return UnitPoint(x: 0.0, y: (normalizedDegree - 90) / 90)
default: return .zero
@odrobnik
odrobnik / yMunch.swift
Created February 8, 2023 21:33
Command Line utility to convert Yahoo Finance CSV export into markdown table for ChatGPT
View yMunch.swift
import SwiftCSV
import Foundation
extension Double {
/// Rounds the double to decimal places value
func rounded(toPlaces places:Int) -> Double {
let divisor = pow(10.0, Double(places))
return (self * divisor).rounded() / divisor
}
}
View RankingsView.view
//
// RankingsView.swift
// ChessClub
//
// Created by Oliver Drobnik on 22.04.22.
//
import SwiftUI
struct RankingsView: View
View Observing.swift
import Foundation
import Combine
import ProoficsSDK
import SwiftUI
class BundleViewModel: ObservableObject
{
@Published var title: String = ""
@Published var subtitle: String?
View FastnotesSettings.swift
import SwiftUI
struct Modifier: Identifiable
{
let id = UUID()
@State var title: String
}
struct FastnotesSettings: View
@odrobnik
odrobnik / PlatformSpecific.swift
Created July 13, 2021 08:01
Platform-specific modifier application
View PlatformSpecific.swift
import SwiftUI
struct Platform: OptionSet
{
let rawValue: Int
static let iOS = Platform(rawValue: 1<<0)
static let tvOS = Platform(rawValue: 1<<1)
static let watchOS = Platform(rawValue: 1<<2)
@odrobnik
odrobnik / NavPicker.swift
Last active February 9, 2021 11:59
Trying to emulate Picker behaviour inside a List
View NavPicker.swift
//
// NavPicker.swift
// ColorCore Demo
//
// Created by Oliver Drobnik on 09.02.21.
//
import SwiftUI
public struct NavPicker<Label, Items> : View where Label : View, Items: CustomStringConvertible & Identifiable
@odrobnik
odrobnik / ContentView.swift
Last active August 15, 2020 09:50
So far it outputs the frames of the cells, but I am stuck trying to hide the ones that are outside of the widget
View ContentView.swift
import SwiftUI
struct RegularEventCell: View {
let color: Color
let title: String
let description: String?
var body: some View {
View Refreshable.swift
@objc protocol Refreshable
{
/// The refresh control
var refreshControl: UIRefreshControl? { get set }
/// The table view
var tableView: UITableView! { get set }
/// the function to call when the user pulls down to refresh
@objc func handleRefresh(_ sender: Any);
View expectation.swift
func testHangSquareBracket()
{
let input = "Text [-( Text"
let expectation = self.expectation(description: "Should not hang")
DispatchQueue.global().async {
let builder = BBCodeAttributedStringBuilder(bbcode: input)
let output = builder.attributedString
XCTAssertNotNil(output)