Skip to content

Instantly share code, notes, and snippets.

View AvdLee's full-sized avatar
👇
avanderlee.com

Antoine van der Lee AvdLee

👇
avanderlee.com
View GitHub Profile
@AvdLee
AvdLee / KeyTimeValues.swift
Last active August 1, 2023 19:30
KeyTimeValues Coding Challenge
let keyTimeValues: [TimeInterval: Float] = [
0.4: 0.0,
0.45: 1.0,
0.475: 1.0,
0.5: 1.0,
0.525: 1.0,
0.55: 0.0,
0.575: 1.0,
0.6: 1.0,
0.65: 1.0,
@AvdLee
AvdLee / ProductViews.swift
Created September 29, 2022 07:18
Product Views Example
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
HStack(spacing: 10) {
ProductView(
title: "Monthly",
label: "POPULAR",
price: "€23",
tintColor: Color(uiColor: UIColor(red: 0.93, green: 0.79, blue: 0.47, alpha: 1.00)),
@AvdLee
AvdLee / HorizontalScrolling.swift
Created February 9, 2022 07:54
Horizontal Scroll in StockAdvisor
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 0) {
ForEach(viewModel.criteria(for: category), id: \.valueProvider.title) { criteria in
StockCriteriaView(criteria: criteria)
.frame(width: UIScreen.main.bounds.width - 60)
.padding(.trailing, 12)
}
}
}.frame(width: UIScreen.main.bounds.width - 48)
.padding(.horizontal, 14)
class Content: NSManagedObject {
// MARK: - Mappable
func mapValues(using mapper: Mapping) throws {
let mapper = try mapper.mapper(for: self, destination: CKContent.self)
mapper.map(\.objectID, \.identifier, transform: { objectID -> String in
return objectID.uriRepresentation().absoluteString
})
mapper.map(\.name, \.name)
mapper.map(\.url, \.url)
mapper.map(\.downloadURLExpiry, \.downloadURLExpiry)
//
// ContentMapper.swift
//
//
// Created by Antoine van der Lee on 09/03/2021.
//
import Foundation
import ContentKit
@AvdLee
AvdLee / ContentMapping.swift
Last active March 9, 2021 13:30
Mapping from Core Data to a class and reversed
import Cocoa
open class Content: Mappable {
var name: String = ""
init(name: String = "") {
self.name = name
}
func mapValues(using mapper: Mapping) throws {
@AvdLee
AvdLee / IssuesCountQualityCheck.swift
Created April 10, 2020 08:35
A quality check for a repository issues count
struct IssuesCountQualityCheck: RepositoryQualityCheck {
let id: String = UUID().uuidString
let title = "Issues count"
let score: Int
init(repository: Repository) {
switch repository.issuesCount {
case 0..<10:
score = 100
case 10..<20:
@AvdLee
AvdLee / FileManagerExtensions.swift
Last active November 19, 2023 23:23
Easily print out useful locations for usage during debugging on the Simulator.
extension FileManager {
/*
Prints out the locations of the simulator and the shared group folder.
This is useful for debugging file issues.
Example usage: FileManager.default.printFileLocations()
*/
func printFileLocations() {
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let simulatorFolder = paths.last!
@AvdLee
AvdLee / DarwinNotificationCenter.swift
Last active January 23, 2024 07:55
A notification center for Darwin Notifications. MIT License applies.
//
// DarwinNotificationCenter.swift
//
// Copyright © 2017 WeTransfer. All rights reserved.
//
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {
@AvdLee
AvdLee / largest-file.sh
Last active December 10, 2023 19:24
Find your project's Swift file with the most lines of code
find . -type f -name "*.swift" -exec grep -H -c '[^[:space:]]' {} \; | \sort -nr -t":" -k2 | awk -F: '{printf("Your largest file %s contains: %s lines \n", $1, $2); exit;}'