Skip to content

Instantly share code, notes, and snippets.

View KaQuMiQ's full-sized avatar

Kacper Kaliński KaQuMiQ

View GitHub Profile
@KaQuMiQ
KaQuMiQ / ReduxExperiment.swift
Created January 30, 2019 17:23
ReduxExperiment.swift
import UIKit
public final class ModuleController<State, Update, Message, Task> {
private var state: State
private var reducer: (inout State, Message) -> ([Update], [Task])
private var worker: (ModuleController, Task) -> Void
private var presenter: (Update) -> Void
public init(state: State,
reducer: @escaping (inout State, Message) -> ([Update], [Task]),
@KaQuMiQ
KaQuMiQ / ModuleController.swift
Last active February 5, 2019 10:46
RedSwift - Redux inspired iOS application architecture
import Foundation
public final class ModuleController<Module: ModuleDescription> {
public var uiComponent: UIComponent { return presenter.uiComponent }
private var state: Module.State
private let dispatcher: (inout Module.State, Module.Message) -> (changes: [Module.Change], tasks: [Module.Task])
private let worker: (@escaping (Module.Message) -> Void, Module.Task) -> Void
private var presenter: Module.Presenter
public init(state: Module.State,
@KaQuMiQ
KaQuMiQ / manage.py
Last active February 25, 2019 13:48
Python manage environment
import sys
import os
import subprocess
import venv
import runpy
import logging
import requirements
def run(dev_env: bool):
@KaQuMiQ
KaQuMiQ / Dockerfile
Created June 13, 2019 09:45
Swift Docker from scratch
ARG SWIFT_VERSION="5.0.1"
# builder image
FROM swift:${SWIFT_VERSION} as builder
RUN apt-get -qq update && apt-get install -y \
libssl-dev zlib1g-dev \
&& rm -r /var/lib/apt/lists/*
# compile application
WORKDIR /app
import Foundation
public protocol Executor {
func execute(_ task: @escaping () -> Void)
}
extension DispatchQueue: Executor {
@inlinable public func execute(_ task: @escaping () -> Void) {
async(execute: task)
import Darwin
internal enum AtomicFlag {
internal typealias Pointer = UnsafeMutablePointer<atomic_flag>
@inline(__always)
internal static func make() -> Pointer {
let pointer = Pointer.allocate(capacity: 1)
pointer.pointee = atomic_flag()
@KaQuMiQ
KaQuMiQ / DataCoding.swift
Last active October 19, 2019 14:49
Declarative network client in swift
import Foundation
public protocol DataEncoder {
func encode<T>(_ value: T) throws -> Data where T: Encodable
}
extension JSONEncoder: DataEncoder {}
public protocol DataDecoder {
func decode<T>(_ type: T.Type, from data: Data) throws -> T where T: Decodable
@KaQuMiQ
KaQuMiQ / Example.swift
Created October 23, 2019 07:03
Functional programming for functional scared
extension Style where T: UILabel {
public func font(_ weight: UIFont.Weight, size: CGFloat) -> Style<T> {
return with { label in
label.font = UIFont.systemFont(ofSize: size, weight: weight)
}
}
public func color(_ color: UIColor) -> Style<T> {
return with { label in
label.textColor = color
@KaQuMiQ
KaQuMiQ / UserDefaultsProperty.swift
Created October 23, 2019 07:10
UserDefaults property wrapper
import Foundation
internal protocol AnyOptional {
var isNone: Bool { get }
}
extension Optional: AnyOptional {
var isNone: Bool {
switch self {
case .none: return true
@KaQuMiQ
KaQuMiQ / KeyboardAwareVC.swift
Last active April 10, 2020 12:23
Keyboard aware ViewController based on safeArea
import UIKit
import ObjectiveC
private var originalAdditionalSafeAreaInsetsKey: Int = 0
open class KeyboardAwareViewController: UIViewController {
open class var backgroundTapEditingEndHandlerEnabled: Bool { true }
private var originalAdditionalSafeAreaInsets: UIEdgeInsets? {
get {