Skip to content

Instantly share code, notes, and snippets.

View finestructure's full-sized avatar

Sven A. Schmidt finestructure

View GitHub Profile
@vzsg
vzsg / (1) Environment+EnvFile.swift
Last active September 19, 2019 08:47
Simple .env file injector for Vapor 3
import Foundation
import Service
#if os(Linux)
import Glibc
#else
import Darwin
#endif
extension Environment {
@rknightuk
rknightuk / mastondon.css
Last active December 26, 2018 12:21
mastodon.social user styles for Fluid
/**
Make toolbar go to the left below 650px
*/
@media screen and (max-width: 650px) {
.ui {
flex-direction: row!important;
}
.tabs-bar {
flex-direction: column!important;
public struct BoundedSequence<Base>: Sequence, IteratorProtocol where Base: Sequence {
public struct Boundary: Equatable {
public let isStart: Bool
public let isEnd: Bool
}
private var _iterator: Base.Iterator
private var _previous: Base.Element?
private var _current: Base.Element?
private var _next: Base.Element?
@nicklockwood
nicklockwood / Withable.swift
Created January 28, 2019 12:06
Withable.swift
/// Withable is a simple protocol to make constructing
/// and modifying objects with multiple properties
/// more pleasant (functional, chainable, point-free)
public protocol Withable {
init()
}
public extension Withable {
/// Construct a new instance, setting an arbitrary subset of properties
init(with config: (inout Self) -> Void) {
@AliSoftware
AliSoftware / Bindings.swift
Last active May 22, 2024 08:45
Re-implementation of @binding and @State (from SwiftUI) myself to better understand it
/*:
This is a concept re-implementation of the @Binding and @State property wrappers from SwiftUI
The only purpose of this code is to implement those wrappers myself
just to understand how they work internally and why they are needed,
⚠️ This is not supposed to be a reference implementation nor cover all
subtleties of the real Binding and State types.
The only purpose of this playground is to show how re-implementing
them myself has helped me understand the whole thing better
//
// ContentView.swift
// Layout
//
// Created by Matt Gallagher on 7/6/19.
// Copyright © 2019 Matt Gallagher. All rights reserved.
//
import SwiftUI
@scottmatthewman
scottmatthewman / AdaptsToSoftwareKeyboard.swift
Last active April 19, 2024 12:56
An example of using Combine to automatically adapt a SwiftUI scrollable view to accommodate an iOS onscreen keyboard
import SwiftUI
import Combine
struct AdaptsToSoftwareKeyboard: ViewModifier {
@State var currentHeight: CGFloat = 0
func body(content: Content) -> some View {
content
.padding(.bottom, currentHeight)
.edgesIgnoringSafeArea(.bottom)
@cdmcmahon
cdmcmahon / PointFreeStateManagement.swift
Last active November 6, 2019 23:51
In the Point-Free series on application architecture and state management, they define a series of ways to compose reducers. Sometimes, however, it seems that the signature of reducers can complicate the signature of these different compositions. I found creating a typealias for reducers separated the concern of understanding the concept of redu…
// In the Point-Free series on application architecture and state management,
// they define a series of ways to compose reducers. Sometimes, however, it seems
// that the signature of reducers can complicate the signature of these different
// compositions. I found creating a typealias for reducers separated the concern of
// understanding the concept of reducers and understanding their higher order
// constructions, especially when starting to write my own.
// Adding a typealias for Reducer can make certain parts a bit more readable
typealias Reducer<Value, Action> = (inout Value, Action) -> Void
extension Publisher {
func cancellable<Id: Hashable>(id: Id) -> AnyPublisher<Output, Failure> {
return Deferred { () -> PassthroughSubject<Output, Failure> in
cancellables[id]?.cancel()
let subject = PassthroughSubject<Output, Failure>()
cancellables[id] = self.subscribe(subject)
return subject
}
.eraseToAnyPublisher()
@AliSoftware
AliSoftware / CustomMatcher.swift
Last active January 5, 2020 21:40
Add custom pattern matching to make your switch statements magical
struct CustomMatcher<Value> {
let closure: (Value) -> Bool
static func ~= (caseValue: CustomMatcher<Value>, switchValue: Value) -> Bool {
caseValue.closure(switchValue)
}
static func ~= (caseValue: Value, switchValue: CustomMatcher<Value>) -> Bool {
switchValue.closure(caseValue)
}
}