Skip to content

Instantly share code, notes, and snippets.

View wildthink's full-sized avatar

Jason Jobe wildthink

  • 21:56 (UTC -04:00)
View GitHub Profile
@wildthink
wildthink / SnapCarousel.swift
Created September 8, 2021 09:54 — forked from xtabbas/SnapCarousel.swift
A carousel that snap items in place build on top of SwiftUI
//
// SnapCarousel.swift
// prototype5
//
// Created by xtabbas on 5/7/20.
// Copyright © 2020 xtadevs. All rights reserved.
//
import SwiftUI
@wildthink
wildthink / TwoWaySnapList.swift
Created September 1, 2021 03:18 — forked from sameersyd/TwoDirectionalSnapList.swift
SwiftUI - Two Directional SnapList
// Checkout the explanation article here - https://sameer-syd.medium.com/swiftui-two-directional-snaplist-95cb852957be
import SwiftUI
import Combine
struct HomeView: View {
@StateObject var viewModel: HomeViewModel
@wildthink
wildthink / ScrollableView.swift
Created August 31, 2021 21:12 — forked from jfuellert/ScrollableView.swift
A scrollable SwiftUI view, UIScrollView wrapper. ScrollableView lets you read and write content offsets for scrollview in SwiftUI, with and without animations.
import SwiftUI
struct ScrollableView<Content: View>: UIViewControllerRepresentable, Equatable {
// MARK: - Coordinator
final class Coordinator: NSObject, UIScrollViewDelegate {
// MARK: - Properties
private let scrollView: UIScrollView
var offset: Binding<CGPoint>
@wildthink
wildthink / EasyMeasurements.swift
Last active November 10, 2021 04:12
Syntactic Sugar for Measurements in Swift
import Foundation
public typealias Mass = Measurement<UnitMass>
public typealias Duration = Measurement<UnitDuration>
public typealias Angle = Measurement<UnitAngle>
public typealias Length = Measurement<UnitLength>
public typealias Speed = Measurement<UnitSpeed>
public extension Measurement where UnitType: Dimension {
static var zero: Measurement<UnitType> {
@wildthink
wildthink / property-key-paths.swift
Created May 29, 2021 15:37 — forked from rxwei/property-key-paths.swift
StoredPropertyIterable + CustomKeyPathIterable
//============================================================================//
// Part 1. StoredPropertyIterable
// This models the purely static layout of a struct.
//============================================================================//
// This is an implementation detail that is required before PAT existentials are
// possible.
protocol _StoredPropertyIterableBase {
static var _allStoredPropertiesTypeErased: [AnyKeyPath] { get }
static var _recursivelyAllStoredPropertiesTypeErased: [AnyKeyPath] { get }
@wildthink
wildthink / line.swift
Created April 17, 2021 13:10 — forked from GrantMeStrength/line.swift
Drawing a line between two points in SceneKit / iOS / Swift
func line(from p1: SCNVector3, to p2: SCNVector3) -> SCNNode? {
// Draw a line between two points and return it as a node
var indices = [Int32(0), Int32(1)]
let positions = [p1, p2]
let vertexSource = SCNGeometrySource(vertices: positions)
let indexData = Data(bytes: &indices, count:MemoryLayout<Int32>.size * indices.count)
let element = SCNGeometryElement(data: indexData, primitiveType: .line, primitiveCount: 1, bytesPerIndex: MemoryLayout<Int32>.size)
let line = SCNGeometry(sources: [vertexSource], elements: [element])
let lineNode = SCNNode(geometry: line)
@resultBuilder
struct StringBuilder {
static func buildBlock(_ components: String...) -> String {
let filtered = components.filter { $0 != "" }
return filtered.joined(separator: "⭐️")
}
static func buildOptional(_ component: String?) -> String {
return component ?? ""
@wildthink
wildthink / OptionSetInfo.swift
Created June 19, 2020 17:43
BitMask OptionSets w/ Associated Structures
struct WeekdaySet: OptionSet {
struct Info {
var name: String
var index: Int
}
static var info:[Int:Info] = [:]
let rawValue: UInt8
init(rawValue: UInt8) {
/*
https://exchangerate.host/#/faq
var requestURL = 'https://api.exchangerate.host/convert?from=USD&to=EUR';
var request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'json';
request.send();
request.onload = function() {
@wildthink
wildthink / Tokenizer.swift
Last active April 19, 2020 04:12
Simple Tokenizer w/ read() option to create Arrays of tokens delimited by parans, brackets, and braces.
//
// Tokenizer.swift
//
// Created by Jason Jobe on 4/15/20.
// Copyright © 2020 Jason Jobe. All rights reserved.
//
public struct Tokenizer {
public struct ReadError: Error {
var str: String
var pos: Int