Skip to content

Instantly share code, notes, and snippets.

View heestand-xyz's full-sized avatar

Anton Heestand heestand-xyz

View GitHub Profile
@heestand-xyz
heestand-xyz / ClampedValue.swift
Created June 12, 2020 07:09
Swift - Property Wrapper - Clamped Value
@propertyWrapper
struct ClampedValue<F: FloatingPoint> {
var value: F
let min: F?
let max: F?
init(wrappedValue: F, min: F? = nil, max: F? = nil) {
value = wrappedValue
self.min = min
self.max = max
}
@heestand-xyz
heestand-xyz / highlight-js_xcode-dark-mode.css
Last active December 23, 2023 05:13
Highlight.js - Style Sheet - Xcode Dark Mode
/*
//
// xcode-dark-mode.css
// Xcode Dark Mode
//
// Created by Hexagons on 2020-06-11.
// http://hexagons.net/
//
*/
public extension UIDevice {
static let modelName: String = {
var systemInfo = utsname()
uname(&systemInfo)
let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}
@heestand-xyz
heestand-xyz / blur_view.swift
Created April 5, 2020 15:00
SwiftUI - View - Blur
import SwiftUI
struct BlurView: UIViewRepresentable {
let style: UIBlurEffect.Style
func makeUIView(context: UIViewRepresentableContext<BlurView>) -> UIVisualEffectView {
UIVisualEffectView(effect: UIBlurEffect(style: style))
}
func csv(named name: String) -> [[String]]? {
guard let url: URL = Bundle.main.url(forResource: name, withExtension: "csv") else { return nil }
return csv(url: url)
}
func csv(url: URL) -> [[String]]? {
guard let text: String = try? String(contentsOf: url) else { return nil }
return csv(text: text)
}
@heestand-xyz
heestand-xyz / cases.swift
Last active August 7, 2020 19:21
Swift Cases
import Foundation
fileprivate let badChars = CharacterSet.alphanumerics.inverted
public extension String {
var camelToTitleCased: String {
if self.count <= 1 {
return self.uppercased()
}
import SwiftUI
struct DileView<Content: View>: View {
let kColCount: Int = 3
let scale: CGFloat
let defaultIndex: Int
let options: () -> ([Content])
let selected: (Int) -> ()
@State var index: Int = 0
@State var open: Bool = false
@heestand-xyz
heestand-xyz / liquid.swift
Created September 27, 2019 13:26
PixelKit - Liquid
PixelKit.main.bits = ._16
let ply = PolygonPIX()
ply.radius = 0.125
let feed = ply._feed(0.99) { feed in
feed._noiseDisplace(distance: 0.01, zPosition: .live / 10, octaves: 10)
}
return feed._edge(100)._quantize(0.1)._edge(10)
@heestand-xyz
heestand-xyz / image-resize.swift
Last active November 20, 2019 07:04
Image Resize - Aspect Fit / Fill
public enum ImagePlacement {
case fill
case fit
}
public static func resize(_ image: UIImage, to size: CGSize, placement: ImagePlacement = .fill) -> UIImage {
let frame: CGRect
switch placement {
case .fit:
// QLPreviewControllerDataSource
var medaUrl: URL?
// MARK: - Quick Look
func quickLook(_ url: URL) {
medaUrl = url
let previewController = QLPreviewController()
previewController.dataSource = self