Skip to content

Instantly share code, notes, and snippets.

@minsOne
minsOne / Data+PrettyPrint.swift
Created October 24, 2022 01:36 — forked from cprovatas/Data+PrettyPrint.swift
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@minsOne
minsOne / AccessibilityPreview.swift
Created October 18, 2022 10:31 — forked from Sherlouk/AccessibilityPreview.swift
SwiftUI view for adding accessibility previews. Proof of concept.
import SwiftUI
import UIKit
// from https://github.com/cashapp/AccessibilitySnapshot
import AccessibilitySnapshotCore
struct AccessibilityPreview<Content: View>: View {
let content: Content
var body: some View {
import RxSwift
import RxCocoa
@dynamicMemberLookup
protocol DynamicMemberLookupableObservableType: AssociateObservable {
subscript<T>(dynamicMember keyPath: KeyPath<Value, T>) -> Observable<T> { get }
}
extension DynamicMemberLookupableObservableType {
subscript<T>(dynamicMember keyPath: KeyPath<Value, T>) -> Observable<T> {
@minsOne
minsOne / query-param.codable.swift
Created July 14, 2021 04:35 — forked from RobertMenke/query-param.codable.swift
Swift Codable to URL Query String
import Foundation
import DictionaryCoding
/// Note: This relies on the DictionaryCoding package https://github.com/elegantchaos/DictionaryCoding
struct QueryParamEncoder {
func encode<T: Encodable>(_ item: T) throws -> String {
let encoder = DictionaryEncoder()
let encoded: [String: Any] = try encoder.encode(item)
let queryParams = encodeDictionary(encoded)
@minsOne
minsOne / KaleidoscopeView.swift
Created March 18, 2021 05:06 — forked from izakpavel/KaleidoscopeView.swift
An animation with a kaleidoscope effect
import SwiftUI
struct HalfShape: Shape {
let left: Bool
func path(in rect: CGRect) -> Path {
return Path { path in
let width = rect.width
let height = rect.height
@minsOne
minsOne / ContinuousStarRating.swift
Created December 6, 2020 23:37 — forked from CodeSlicing/ContinuousStarRating.swift
Demonstrates using relative offset on mask to control visibility of masked star rating so the color is continuous behind the stars rather than on or off for each one
//
// ContinuousStarRating.swift
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
@minsOne
minsOne / RotatorView.swift
Created December 3, 2020 09:05 — forked from izakpavel/RotatorView.swift
a SwiftUI recreation of an interesting animation by @beesandbombs
//
// RotatorView.swift
//
// Created by Pavel Zak on 16/11/2020.
// original idea by: https://twitter.com/beesandbombs/status/1326312738033983489?s=20
//
import SwiftUI
func pow(_ x: Int, _ y: Int) -> Int {
@minsOne
minsOne / LightningView.swift
Created December 3, 2020 09:05 — forked from izakpavel/LightningView.swift
Lightnings in SwiftUI
//
// Lightnings fun
//
// BEWARE highly unoptimized!
//
// Created by Pavel Zak on 30/11/2020.
//
import SwiftUI
@minsOne
minsOne / DynamicUserDefaults.swift
Created November 27, 2020 04:57 — forked from marty-suzuki/DynamicUserDefaults.swift
Sample usage of Swift 5.1 dynamicMemberLookup that supports KeyPath.
import Foundation
@dynamicMemberLookup
final class DynamicUserDefaults {
static var standard: DynamicUserDefaults {
return DynamicUserDefaults(.standard)
}
private let keys = Keys()
// Modified from @mutsuda's https://medium.com/@mutsuda/create-an-ios-widget-showing-google-spreadsheets-data-856767a9447e
// by @levelsio
// HOW TO
// 1) Make a Google Sheet, we'll pull the first cell e.g. A1
// 2) Publish your Google Sheet, File -> Publish To Web
// 3) Copy the SHEET_ID in the URL, put it in here below:
const endpoint = "https://spreadsheets.google.com/feeds/cells/SHEET_ID/1/public/full?alt=json"
// 4) Install Scriptable @ https://apps.apple.com/us/app/scriptable/id1405459188
// 5) Copy this entire script in to Scriptable (tip: you can send it to your iPhone via Whatsapp/Messenger/Telegram etc)