Skip to content

Instantly share code, notes, and snippets.

View bugrym's full-sized avatar
🥋
Focusing

Vladyslav bugrym

🥋
Focusing
  • Ukraine
View GitHub Profile
import Foundation
import CoreData
class CoreDataStack {
// MARK: - Core Data stack
lazy var persistentContainer: NSPersistentContainer = {
/*
The persistent container for the application. This implementation
creates and returns a container, having loaded the store for the
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var coreDataStack = CoreDataStack()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let navigationController = window?.rootViewController as! UINavigationController
private func buildTree(allProducts:[Product], handler: @escaping(()->Void)) {
let group = DispatchGroup()
let asyncQueue = DispatchQueue(label: "com.shop.tree.build.queue", qos: .utility, attributes: .concurrent, autoreleaseFrequency: .inherit, target: nil)
var byCategory:[ProductSection] = []
group.enter()
asyncQueue.async {
for product in allProducts {
@bugrym
bugrym / Keyboard_handler
Created November 18, 2019 11:38
Keyboard handler
@objc func adjustForKeyboard(notification: Notification) {
guard let keyboardValue = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue else { return }
let keyboardScreenEndFrame = keyboardValue.cgRectValue
let keyboardViewEndFrame = view.convert(keyboardScreenEndFrame, from: view.window)
if notification.name == UIResponder.keyboardWillHideNotification {
scrollView.contentInset.bottom = self.logInButton.frame.height
} else {
//
// PaneViewController.swift
// PaneApp
//
// Created by Vladyslav Bugrym on 18.02.2020.
// Copyright © 2020 admin. All rights reserved.
//
import UIKit
@bugrym
bugrym / UIImageView extension
Created February 18, 2020 12:45
UIImageView with a convenience initializer that allows us to include the insets
extension UIImageView {
convenience init(named name: String, top: CGFloat, left:
CGFloat, bottom: CGFloat, right: CGFloat) {
let insets = UIEdgeInsetsMake(top, left, bottom, right) let originalImage = UIImage(named: name)
let insetImage = originalImage?.withAlignmentRectInsets(insets) self.init(image: insetImage)
}
}
@bugrym
bugrym / leetCode
Created February 20, 2020 15:55
771. Jewels and Stones
func numJewelsInStones(_ J: String, _ S: String) -> Int {
var counter = 0
let stones = Array(S)
let jewels = Array(J)
for i in 0..<stones.count {
for j in 0..<jewels.count {
let lhs = stones[i]
let rhs = jewels[j]
@bugrym
bugrym / leetCode1
Created February 20, 2020 15:56
1108. Defanging an IP Address
func defangIPaddr(_ address: String) -> String {
return address.replacingOccurrences(of: ".", with: "[.]")
}
@bugrym
bugrym / leetCode2
Created February 21, 2020 08:50
1281. Subtract the Product and Sum of Digits of an Integer
func subtractProductAndSum(_ n: Int) -> Int {
var givenNum = n
var num:[Int] = []
if n >= 1 && n <= 100000 {
repeat {
let digit = givenNum%10
givenNum /= 10
num.append(digit)
} while (givenNum != 0)
@bugrym
bugrym / leetCode3
Created February 21, 2020 09:26
1295. Find Numbers with Even Number of Digits
func findNumbers(_ nums: [Int]) -> Int {
var res = 0
if nums.count >= 1 && nums.count <= 500 {
nums.map {
if $0 >= 1 && $0 <= 100000 {
var givenNum = $0
var digits:[Int] = []
repeat {