Skip to content

Instantly share code, notes, and snippets.

View cliss's full-sized avatar

Casey Liss cliss

View GitHub Profile
@cliss
cliss / IteratorPlayground.swift
Created December 18, 2019 14:35
Playground contents showing the use of AnyIterator<T>
import Foundation
class ListOfIntegers: Sequence {
typealias Element = Int
private var backingStore = [Int]()
init() {}
init(_ value: [Int]) {
self.backingStore = value
}
import UIKit
public typealias RowSectionPair = (row: Int, section: Int)
extension IndexPath: RawRepresentable {
public typealias RawValue = RowSectionPair
public init?(rawValue: RowSectionPair) {
self = IndexPath(row: rawValue.row, section: rawValue.section)
}
@cliss
cliss / mergechapters.py
Created January 26, 2021 14:30
Merge Files with Chapters
import datetime
import json
import os
import subprocess
import sys
#############
### USAGE ###
#############
@cliss
cliss / MatchingHeightsPlaygroundPage.swift
Created February 2, 2021 14:39
Matching Heights Techniques
import UIKit
import SwiftUI
import PlaygroundSupport
/* *****************************************
* GeometryReader with PreferenceKey
* *****************************************/
struct HeightPreferenceKey: PreferenceKey {
static let defaultValue: CGFloat = 0
@cliss
cliss / RatingsFetcher.swift
Created May 21, 2022 00:35
Fetching Ratings
import Foundation
import Combine
public struct RatingsFetcher {
/// Asynchronously gets the number of ratings for the current version of the given app.
/// - Parameter appId: App ID to look up
/// - Returns: Count of ratings for the current version
public static func ratingsForCurrentVersion(appId: Int) async throws -> Int {
guard let url = URL(string: "https://itunes.apple.com/lookup?id=\(appId)") else {
@cliss
cliss / Example.swift
Last active February 6, 2023 12:31
Decoding a heterogenous JSON array
// This is intended to be dropped in a Playground.
import Foundation
let json =
"""
{
"name": "Casey's Corner",
"menu": [
{
@cliss
cliss / Playground.swift
Last active May 12, 2023 14:18
List{} Gets Me Again
//: A UIKit based Playground for presenting user interface
import SwiftUI
import PlaygroundSupport
struct SlideDemo: View {
@State var activePage = 0
var body: some View {
// Change this VStack to a List and the animation breaks