Skip to content

Instantly share code, notes, and snippets.

View nerdsupremacist's full-sized avatar
🏠
#stayhome

Mathias Quintero nerdsupremacist

🏠
#stayhome
View GitHub Profile
@nerdsupremacist
nerdsupremacist / GridView.swift
Last active November 14, 2022 14:25
Grid View with View Builder SwiftUI
import SwiftUI
struct GridView: View {
let columns: Int
let columnAlignment: VerticalAlignment
let rowAlignment: HorizontalAlignment
let rowSpacing: CGFloat?
let columnSpacing: CGFloat?
let content: [AnyView]
@nerdsupremacist
nerdsupremacist / View+binding.swift
Created January 13, 2020 10:06
Set up bindings for Combine Publishers within the lifecycle of a SwiftUI View
import Foundation
import Combine
import SwiftUI
extension View {
func binding(@CancellableBuilder bindings: @escaping () -> AnyCancellable) -> some View {
return BindingView(content: AnyView(self), bindings: bindings)
}
@nerdsupremacist
nerdsupremacist / Debounced.swift
Last active October 2, 2020 19:41
Debounced Property Wrapped
import SwiftUI
import Combine
@propertyWrapper
struct Debounced<Value>: DynamicProperty {
private class Box: ObservableObject {
let value = PassthroughSubject<Value, Never>()
@Published
private(set) var debounced: Value
@nerdsupremacist
nerdsupremacist / anyView.swift
Created May 20, 2020 17:32
Attempt at creating an AnyView from an Any
private protocol AnyViewConvertible {
func anyView() -> AnyView
}
extension View {
func anyView() -> AnyView {
return AnyView(self)
}
}
@nerdsupremacist
nerdsupremacist / OrderedSet.swift
Created May 13, 2020 03:19
Persistent Cache construct with Hashable Keys
import Foundation
public struct OrderedSet<E: Hashable>: Equatable, Collection {
public typealias Element = E
public typealias Index = Int
public typealias Indices = Range<Int>
private var array: [Element]
@nerdsupremacist
nerdsupremacist / String+camelized.swift
Last active December 25, 2019 17:31 — forked from reitzig/Camelizer.swift
Convert Swift strings to camel case
fileprivate let badChars = CharacterSet.alphanumerics.inverted
extension String {
var uppercasingFirst: String {
return prefix(1).uppercased() + dropFirst().lowercased()
}
var lowercasingFirst: String {
return prefix(1).lowercased() + dropFirst().lowercased()
}
@nerdsupremacist
nerdsupremacist / LargestWords.swift
Created January 23, 2019 14:40
LargestSevenSegmentDisplayableWords
import Foundation
enum ComparisonResult {
case equal
case larger
case smaller
}
extension Comparable {
@nerdsupremacist
nerdsupremacist / Property.dart
Created October 14, 2018 03:20
Property class for MVVM in Flutter
import 'dart:async';
import 'package:flutter/material.dart';
class Property<Value> implements Sink<Value> {
Value _internalValue;
final StreamController<Value> _streamController = StreamController.broadcast();
Value get value {
import Foundation
let fb = [
3 : "Fizz",
5 : "Buzz",
6 : "Fizz",
9: "Fizz",
10: "Buzz",
12: "Fizz",
@nerdsupremacist
nerdsupremacist / SSID.swift
Last active December 11, 2017 13:28 — forked from werediver/WiFiSsid.swift
Get the connected Wi-Fi network SSID on iOS (in Swift).
import Foundation
import SystemConfiguration.CaptiveNetwork
func ssid() -> String? {
let interfaces = CNCopySupportedInterfaces() as [AnyObject]?
let interfaceNames = interfaces?.map { $0 as! CFString }
let interfaceDictionaries = interfaceNames?.flatMap { CNCopyCurrentNetworkInfo($0) as? [String : AnyObject] }
return interfaceDictionaries?.flatMap { $0[kCNNetworkInfoKeySSID as String] as? String }
.first
}