Skip to content

Instantly share code, notes, and snippets.

View SergLam's full-sized avatar
😊
Try to make your code better!

Serhii Liamtsev SergLam

😊
Try to make your code better!
View GitHub Profile
@SergLam
SergLam / Palindrome.swift
Last active January 24, 2020 10:12
Swift - palindrome finding functions
import UIKit
import PlaygroundSupport
let page = PlaygroundPage.current
page.needsIndefiniteExecution = true
func palindrome(for string: String) -> Bool {
let arr = Array(string.lowercased())
// NOTE: from the natural language point of view empty string - is not a palindrome
@SergLam
SergLam / UIApplication+Environment.swift
Created January 16, 2020 18:56
Swift - check iOS app environment (debug OR TestFlight build) at runtime
import UIKit
extension UIApplication {
// MARK: Public
func isRunningInTestFlightEnvironment() -> Bool {
if isSimulator() {
return false
} else {
if isAppStoreReceiptSandbox() && !hasEmbeddedMobileProvision() {
@SergLam
SergLam / locale-capital.json
Created January 15, 2020 15:00
Locale - country capital city datasheet (usefull for map centring)
[
{"locale_key": "bs", "Marathi": "Bosnian",
"capital": {
"name": "New Delhi",
"latitude": 28.6357600,
"longitude": 77.2244500
}
},
{"locale_key": "ee_TG", "Marathi": "Ewe (Togo)",
"capital": {
@SergLam
SergLam / MyProfileSettings+CoreDataClass.swift
Created December 25, 2019 15:03
CoreData example model
import CoreData
import Foundation
// NOTE: use manual / none code generation -
// it give full controll over models properties(custom getters + setters) + model lifecycle
// To create a new model class:
// 1. Focus on core data model class
// 2. XCode -> Editor -> Create NSManagedObject Subclass
// 3. Select an appropriate model from database scheme and create a class
@SergLam
SergLam / CoreDataManager+MyUser.swift
Last active February 2, 2020 05:46
CoreData manager basic setup
import CoreData
import Foundation
extension CoreDataManager {
/**
User profile (id, email, phone, picture_url, social links and ect.)
*/
var myProfileSettings: MyProfileSettings? {
get {
@SergLam
SergLam / UITableView+Refresh.swift
Last active December 9, 2024 18:34
UITableView - safe reload + section headers+footers reload without animation
import UIKit
extension UITableView {
func isCellVisible(section: Int, row: Int) -> Bool {
guard let indexes = self.indexPathsForVisibleRows else {
return false
}
return indexes.contains{ $0.section == section && $0.row == row }
}
@SergLam
SergLam / JSONAble.swift
Last active March 30, 2021 07:16
JSONAble - protocol for network models + send them in app custom Observation infrastructure
import Foundation
import Moya
typealias DataUpdateInfo = [AnyHashable: [String: Any]]
protocol JSONAble where Self: Codable {
func toJSON() -> [String: Any]
static func fromJSON(_ dictionary: [AnyHashable: Any]) -> Self?
func toMultipartData() -> [Moya.MultipartFormData]?
@SergLam
SergLam / AccessibilityConstants.swift
Created December 7, 2019 08:35
Easy XCUITest + Voice over setup using protocol, extension and Rswift
import Foundation
import Rswift // pod 'R.swift'
typealias Localizable = R.string.localizable
// NOTE: Contains accesibility identifiers (XCUITest) + accesibility labels (Voice over support)
struct Accessibility {
// MARK: Chat navigation bar
static let chatNavigationUserProfileImageId = "ChatNavigationBar.chatOpponentAvatar"
@SergLam
SergLam / AppDelegate.swift
Created December 6, 2019 06:41
Stored properties in extension hack:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
var testStr = ""
var testStr2 = "131231"
testStr.test = 20
@SergLam
SergLam / Answer.sql
Last active November 17, 2022 09:50
SQL-ex.ru Ex.29(3)
http://www.sql-ex.ru/learn_exercises.php
Description
The firm owns several buy-back centers for collection of recyclable materials. Each of them receives funds to be paid to the recyclables suppliers. Data on funds received is recorded in the table
Income_o(point, date, inc)
The primary key is (point, date), where point holds the identifier of the buy-back center, and date corresponds to the calendar date the funds were received. The date column doesn’t include the time part, thus, money (inc) arrives no more than once a day for each center. Information on payments to the recyclables suppliers is held in the table
Outcome_o(point, date, out)
In this table, the primary key (point, date) ensures each buy-back center reports about payments (out) no more than once a day, too.
For the case income and expenditure may occur more than once a day, another database schema with tables having a primary key consisting of the single column code is used: