Skip to content

Instantly share code, notes, and snippets.

View jonahaung's full-sized avatar

Aung Ko Min jonahaung

View GitHub Profile
@jonahaung
jonahaung / MediaPicker.swift
Last active November 6, 2019 02:19
Media Picker
//
// UIViewControllerExtension.swift
// Rocket.Chat
//
// Created by Rafael K. Streit on 14/11/16.
// Copyright © 2016 Rocket.Chat. All rights reserved.
//
import UIKit
import Photos
@jonahaung
jonahaung / SerialTaskQueue.swift
Created November 6, 2019 02:03
SerialTaskQueue
mport Foundation
public typealias TaskClosure = (_ completion: @escaping () -> Void) -> Void
public protocol SerialTaskQueueProtocol {
func addTask(_ task: @escaping TaskClosure)
func start()
func stop()
func flushQueue()
var isEmpty: Bool { get }
@jonahaung
jonahaung / Singapore_NRIC_Checker.swift
Created November 16, 2019 16:01
Singapore NRIC Checker
func isSingaporeNRIC(fin :String) -> Bool {
guard fin.count == 9 else { return false }
let str = fin.uppercased()
let characters = [Character](str)
var weight = 0
weight += Int(String(characters[1]))! * 2
weight += Int(String(characters[2]))! * 7
weight += Int(String(characters[3]))! * 6
weight += Int(String(characters[4]))! * 5
weight += Int(String(characters[5]))! * 4
@jonahaung
jonahaung / MyanmarNumbers.swift
Created November 16, 2019 16:04
Myanmar Numbers Converter
import Foundation
protocol MyanmarNumber {}
extension MyanmarNumber {
func toMyanmarNumber() -> String? {
guard let this = self as? NSNumber else {
return nil
}
@jonahaung
jonahaung / TextReader.swift
Created November 16, 2019 16:05
Text Reader
import Foundation
public class TextReader {
let encoding: String.Encoding
let chunkSize: Int
let fileHandle: FileHandle
var buffer: Data
let delimPattern : Data
var isAtEOF: Bool = false
@jonahaung
jonahaung / MyanmarPhoneValidator.swift
Created November 16, 2019 16:05
Myanmar Phone Validator
//
// MyanmarPhoneValidator.swift
// mMsgr
//
// Created by Aung Ko Min on 17/10/19.
// Copyright © 2019 Aung Ko Min. All rights reserved.
//
import Foundation
@jonahaung
jonahaung / AutocompleteTextField.swift
Created November 16, 2019 16:07
Autocomplete TextField
//
// AutocompleteTextView.swift
// mMsgr
//
// Created by Aung Ko Min on 6/9/19.
// Copyright © 2019 Aung Ko Min. All rights reserved.
//
import UIKit
struct RegexParser {
static let hashtagPattern = "(?:^|\\s|$)#[\\p{L}0-9_]*"
static let mentionPattern = "(?:^|\\s|$|[.])@[\\p{L}0-9_]*"
static let urlPattern = "(^|[\\s.:;?\\-\\]<\\(])" +
"((https?://|www\\.|pic\\.)[-\\w;/?:@&=+$\\|\\_.!~*\\|'()\\[\\]%#,☺]+[\\w/#](\\(\\))?)" +
"(?=$|[\\s',\\|\\(\\).:;?\\-\\[\\]>\\)])"
static let phonePattern = "(?:(\\+\\d\\d\\s+)?((?:\\(\\d\\d\\)|\\d\\d)\\s+)?)(\\d{4,5}\\-?\\d{4})"
static let myanmarWordsBreakerPattern = "(?:(?<!\\u1039)([\\u1000-\\u102A\\u103F\\u104A-\\u104F]|[\\u1040-\\u1049]+|[^\\u1000-\\u104F]+)(?![\\u103E\\u103B]?[\\u1039\\u103A\\u1037]))"
import UIKit
func highlightMatches(for pattern: String, inString string: String) -> NSAttributedString {
guard let regex = try? NSRegularExpression(pattern: pattern, options: []) else {
return NSMutableAttributedString(string: string)
}
let range = NSRange(string.startIndex..., in: string)
let matches = regex.matches(in: string, options: [], range: range)
//
// StringTracker.swift
// Myanmar Lens
//
// Created by Aung Ko Min on 24/11/19.
// Copyright © 2019 Aung Ko Min. All rights reserved.
//
import Foundation