Skip to content

Instantly share code, notes, and snippets.

View alexanderkhitev's full-sized avatar
🚀
Focusing

Alexander Khitev alexanderkhitev

🚀
Focusing
View GitHub Profile
@alexanderkhitev
alexanderkhitev / SnapCarousel.swift
Created February 22, 2023 14:38 — forked from xtabbas/SnapCarousel.swift
A carousel that snap items in place build on top of SwiftUI
//
// SnapCarousel.swift
// prototype5
//
// Created by xtabbas on 5/7/20.
// Copyright © 2020 xtadevs. All rights reserved.
//
import SwiftUI
@alexanderkhitev
alexanderkhitev / firstDifferenceBetweenStrings.swift
Created December 8, 2022 18:31 — forked from kristopherjohnson/firstDifferenceBetweenStrings.swift
Swift code to find differences between strings and display them in a readable way, useful for displaying unit test results
import Foundation
/// Find first differing character between two strings
///
/// :param: s1 First String
/// :param: s2 Second String
///
/// :returns: .DifferenceAtIndex(i) or .NoDifference
public func firstDifferenceBetweenStrings(s1: NSString, s2: NSString) -> FirstDifferenceResult {
import Foundation
// Inspired by https://gist.github.com/mbuchetics/c9bc6c22033014aa0c550d3b4324411a
struct JSONCodingKeys: CodingKey {
var stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
import Foundation
import RealmSwift
import ObjectMapper
class RealmUser: Object, Mappable {
dynamic var id = "" // id
dynamic var phoneNumber = ""
dynamic var isMain = false
dynamic var userInfo: RealmUserInfo? = nil
# xcode-version-bump.sh
# @desc Auto-increment the version number (only) when a project is archived for export.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Check the checkbox "Run script only when installing"
# 6. Drag the "Run Script" below "Link Binaries With Libraries"
# 7. Insure your starting version number is in SemVer format (e.g. 1.0.0)
@alexanderkhitev
alexanderkhitev / README.md
Created January 7, 2017 13:44 — forked from simenbrekken/README.md
Firebase NPM doesn't expose the token generator dependency

There are some ways to fix this:

  1. Remove dependency and let users install it manually as needed, the token generator isn't really a hard dependency of Firebase anyway
  2. Expose the dependency from the firebase module:
    var Firebase = require('firebase')
        FirebaseTokenGenerator = Firebase.TokenGenerator
@alexanderkhitev
alexanderkhitev / ArrayTransform.swift
Created December 13, 2016 10:09 — forked from Jerrot/ArrayTransform.swift
Transform arrays with ObjectMapper to Realm's List type
// Based on Swift 1.2, ObjectMapper 0.15, RealmSwift 0.94.1
// Author: Timo Wälisch <timo@waelisch.de>
import UIKit
import RealmSwift
import ObjectMapper
import SwiftyJSON
class ArrayTransform<T:RealmSwift.Object where T:Mappable> : TransformType {
typealias Object = List<T>
@alexanderkhitev
alexanderkhitev / gist:93bee949907d4c482bb8d413800daeda
Last active December 4, 2017 09:23
isValidEmail string extension for swift 3
var isValidEmail: Bool {
do {
let regex = try NSRegularExpression(pattern: "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}", options: .caseInsensitive)
return (regex.firstMatch(in: self, options: [], range: NSMakeRange(0, self.characters.count)) != nil)
} catch {
debugPrint(error.localizedDescription)
return false
}
}
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
## Build generated
build/
DerivedData/
## Various settings
*.pbxuser
func cropRect() -> CGRect {
let cgImage = self.CGImage!
let context = createARGBBitmapContextFromImage(cgImage)
if context == nil {
return CGRectZero
}
let height = CGFloat(CGImageGetHeight(cgImage))
let width = CGFloat(CGImageGetWidth(cgImage))