Skip to content

Instantly share code, notes, and snippets.

View Yerazhas's full-sized avatar
😎
Coding

Yerassyl Zhassuzakhov Yerazhas

😎
Coding
View GitHub Profile
import SwiftUI
struct DatePickerInputView: UIViewRepresentable {
@Binding var date: Date?
let placeholder: String
init(date: Binding<Date?>, placeholder: String) {
self._date = date
self.placeholder = placeholder
}
import SwiftUI
import UIKit
final class DatePickerTextField: UITextField {
@Binding var date: Date?
private let datePicker = UIDatePicker()
init(date: Binding<Date?>, frame: CGRect) {
self._date = date
super.init(frame: frame)
@Yerazhas
Yerazhas / RandomReviewerGenerator.swift
Last active June 15, 2020 07:26
A code snippet for code reviewer assignment
final class Reviewer {
let name: String
var revieweesCount: Int
init(name: String) {
self.name = name
self.revieweesCount = 0
}
}
let vc = BaseMessagesViewController<CFMessageImpl>(messagesSocket: MessagesWSManager(socket: WebSocket(url: URL(string: "randomURL")!)), parser: CFParserImpl())
let vc1 = BaseMessagesViewController<CFMessageImpl>(messagesSocket: MessagesSocketIOManager(urlString: "randomURL"), parser: CFParserImpl())
protocol CFParser {
func parse<T: Decodable>(response: Data) -> Result<T, Error>
}
class CFParserImpl: CFParser {
func parse<T>(response: Data) -> Result<T, Error> where T : Decodable {
return .failure(MessageError.noData)
}
}
protocol CFMessage: Decodable {
var id: Int { get }
}
class CFMessageImpl: CFMessage {
var id: Int
}
class BaseMessagesViewController<Message: CFMessage>: UIViewController {
private var messages = [Message]()
private var currentPage: Int = 1
private var limit: Int = 10
private let messagesSocket: CFMessagesSocket
private let parser: CFParser
init(messagesSocket: CFMessagesSocket, parser: CFParser) {
self.messagesSocket = messagesSocket
self.parser = parser
protocol CFMessagesSocketDelegate: class {
func didReceiveMessage(message: String)
func didReceiveError(error: Error)
func didReceiveData(data: Data)
}
import Starscream
class MessagesWSManager: CFMessagesSocket {
weak var delegate: CFMessagesSocketDelegate?
private let socket: WebSocket
init(socket: WebSocket) {
self.socket = socket
}
import SocketIO
class MessagesSocketIOManager: CFMessagesSocket {
weak var delegate: CFMessagesSocketDelegate?
private let manager: SocketManager
private let socket: SocketIOClient
init(urlString: String) {
self.manager = SocketManager(socketURL: URL(string: urlString)!, config: [.log(true), .compress])
self.socket = manager.defaultSocket