Skip to content

Instantly share code, notes, and snippets.

View wildthink's full-sized avatar

Jason Jobe wildthink

  • 17:44 (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 / 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 / .lldbinit
Created April 9, 2020 17:31 — forked from maxchuquimia/.lldbinit
My .lldbinit
command alias objc expression -l objc -O --
command regex swift 's#(.+)#expression -l Swift -O -- defer { CATransaction.flush() }; %1#'
breakpoint set -n AppDelegate.application --one-shot true --auto-continue true
breakpoint command add
swift import Foundation
swift import UIKit
swift import MyApp_tvOS
swift import MyApp_iOS
swift func $printSubviews(of view: UIView) { print(view.perform("recursiveDescription")!) }
@wildthink
wildthink / CodableExtension.swift
Created March 8, 2020 01:21 — forked from sukov/CodableExtension.swift
Codable (Encode & Decode) [Any] and [String: Any] Swift 5
// Original: https://gist.github.com/loudmouth/332e8d89d8de2c1eaf81875cfcd22e24
import Foundation
private struct JSONCodingKeys: CodingKey {
var stringValue: String
init(stringValue: String) {
self.stringValue = stringValue
}
@wildthink
wildthink / Swift – func deepDescription
Last active July 20, 2018 20:31 — forked from mhuusko5/Swift – func deepDescription
Swift – func deepDescription(any: Any) -> String (pretty print any object, recursively)
func deepDescription(_ any: Any) -> String {
guard let any = deepUnwrap(any) else {
return "nil"
}
if any is Void {
return "Void"
}
if let int = any as? Int {
@wildthink
wildthink / spaceutil.c
Created February 20, 2018 16:55 — forked from camillol/spaceutil.c
Two ways of messing with spaces
#include <unistd.h>
#include <CoreServices/CoreServices.h>
#include <ApplicationServices/ApplicationServices.h>
typedef int CGSConnection;
extern OSStatus CGSGetWorkspace(const CGSConnection cid, int *workspace);
extern OSStatus CGSSetWorkspace(const CGSConnection cid, int workspace);
extern CGSConnection _CGSDefaultConnection(void);
int get_space_id(void);