Skip to content

Instantly share code, notes, and snippets.

View Exey's full-sized avatar

Exey Panteleev Exey

View GitHub Profile
@Exey
Exey / ColorAnimation.swift
Created September 15, 2021 16:48
ColorAnimation.swift
private struct ColorAnimation: AnimatableModifier {
var animatableData: Double
private let rgbaPair: [(Double, Double)]
init(from: Color, to: Color, percentToColor: Double) {
animatableData = percentToColor
let fromComponents = UIColor(from).cgColor.components!
let toComponents = UIColor(to).cgColor.components!
rgbaPair = Array(zip(fromComponents.map(Double.init), toComponents.map(Double.init)))
@Exey
Exey / Mock.swift
Last active September 1, 2021 17:14
Mock.swift
struct Mock {}
extension Mock {
static func decode<T>(forResource: String) -> T? where T: Decodable {
var result: T? = nil
do {
if let path = Bundle.main.path(forResource: forResource, ofType: "json"), let jsonData = try String(contentsOfFile: path).data(using: .utf8) {
result = try JSONDecoder().decode(T.self, from: jsonData)
}
@Exey
Exey / complex.swift
Last active March 3, 2021 22:06
not compilable
let array = [Int]()
let dic = [Int : Double]()
let tuple = array
.map { c -> (a: Int, b: Double) in return (a: c, b: dic[c]!) }
.sorted(by: { (x, y) -> Bool in return x.b == y.b ? x.a < y.a : x.b > y.b }).first!
openapi: 3.0.3
info:
title: NewsAPI
description: NewsAPI.org
version: 1.0.0
servers:
- url: https://newsapi.org/v2
tags:
- name: articles
description: News articles
@Exey
Exey / Blueprint+OpenCombine.swift
Created November 23, 2020 19:11
Blueprint+OpenCombine.swift
import UIKit
import OpenCombine
import BlueprintUI
import BlueprintUICommonControls
typealias Published = OpenCombine.Published
final class CounterViewModel {
@Published var totalCount = 0
@Exey
Exey / Render+OpenCombine.swift
Created November 23, 2020 17:56
Render+OpenCombine.swift
import UIKit
import CoreRender
import Render
import OpenCombine
final class ViewController: UIViewController {
var hostingView: HostingView!
let contex = Context()
var coreRenderView: CounterView?
@Exey
Exey / FluxSwift5_3.swift
Created June 2, 2020 18:21
Flux on Swift 5.3
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let store = Store<Int, CounterAction>(initialState: 0) { previousState, action in
switch action {
case .increment:
return previousState + 1
case .decrement:
return previousState - 1
}
}
func resetUITableViewAppearance() {
UITableView.appearance().separatorStyle = .none
UITableView.appearance().separatorInset = .zero
UITableView.appearance().showsHorizontalScrollIndicator = false
UITableView.appearance().showsVerticalScrollIndicator = false
UITableView.appearance().layoutMargins = .zero
UITableView.appearance().contentInset = .zero
UITableView.appearance().contentOffset = .zero
UITableViewCell.appearance().selectionStyle = .none
UITableViewCell.appearance().separatorInset = .zero
import SwiftUI
extension AnyTransition {
static var moveUpAndFade: AnyTransition {
let insertion = AnyTransition.move(edge: .top).combined(with: .opacity)
let removal = AnyTransition.move(edge: .top).combined(with: .opacity)
return .asymmetric(insertion: insertion, removal: removal)
}
import simd
extension float4x4 {
init(scaleBy s: Float) {
self.init(SIMD4<Float>(s, 0, 0, 0),
SIMD4<Float>(0, s, 0, 0),
SIMD4<Float>(0, 0, s, 0),
SIMD4<Float>(0, 0, 0, 1))
}