Skip to content

Instantly share code, notes, and snippets.

View Catherine-K-George's full-sized avatar

Catherine George Catherine-K-George

View GitHub Profile
@Catherine-K-George
Catherine-K-George / SQS.swift
Last active October 15, 2021 13:40
How to deliver single & batch messages to a specified Amazon SQS Queue in Swift
import AWSSQS
class SQS {
func send(_ model: Encodable, to queueURL: String) -> () {
guard let messageString = model.jsonString() else { return }
let sqs = AWSSQS.default()
let sendMsgRequest = AWSSQSSendMessageRequest()
sendMsgRequest?.queueUrl = queueURL
sendMsgRequest?.messageBody = messageString
@Catherine-K-George
Catherine-K-George / RenameCommitAuthor.sh
Last active October 15, 2021 13:31
Change commit author with different email
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="oldgmail@gmail.com"
CORRECT_NAME="New user name"
CORRECT_EMAIL="newgmail@gmail.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
export GIT_COMMITTER_NAME="$CORRECT_NAME"
export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
@Catherine-K-George
Catherine-K-George / Dates+Extension.swift
Created June 13, 2021 11:15
Hours ago text for chat time labels + Swift
extension Date {
func differenceFromNow() -> DateComponents {
return Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: self, to: Date())
}
}
extension DateComponents {
func agoString() -> String {
if let year = year, year > 0 {
return "\(year) \(year > 1 ? "years" : "year") ago"
@Catherine-K-George
Catherine-K-George / SegmentControl.swift
Created June 9, 2021 18:11
UISegmentControl with underline
extension UISegmentedControl {
private var underlineWidth: CGFloat { 20 }
private var underlineHeight: CGFloat { 2 }
private var segmentWidth: CGFloat {
bounds.width / CGFloat(numberOfSegments)
}
@Catherine-K-George
Catherine-K-George / SearchViewController.swift
Last active June 6, 2021 16:57
Swift - Dispatch Work Item to show search bar typeahead results
import UIKit
class SearchViewController: UIViewController {
private var searchWorkItem: DispatchWorkItem?
override func viewDidLoad() {
super.viewDidLoad()
}
@Catherine-K-George
Catherine-K-George / OTP.swift
Created June 6, 2021 12:55
iOS Swift - OTP Auto fill to multiple textfields
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
var nextTextfieldTag = 0
if string.isEmpty {
return true
} else if string.count == 1 { // Auto fill OTP to multiple textfield
textField.text = string
nextTextfieldTag = textField.tag + 1
} else if string.count == maximumDigits { // Paste OTP to multiple textfield
var pastedOTP = string
for tag in 1...maximumDigits {
@Catherine-K-George
Catherine-K-George / Error.swift
Last active June 7, 2021 18:44
Swift AWS Cognito exception handler with customized descriptions
import AWSCognitoIdentityProvider
extension Error {
var customizedDescription: String {
let nsError = self as NSError
if nsError.domain == AWSCognitoIdentityProviderErrorDomain, let code = AWSCognitoIdentityProviderErrorType(rawValue: nsError.code) {
switch code {
case .expiredCode: return "Verification code has expired. Please try again"
case .codeMismatch: return "Incorrect verification code. Please enter the correct code to continue."
case .notAuthorized: return "Authentication failed. Please enter the correct credentials to continue."
@Catherine-K-George
Catherine-K-George / UILabel+Extensions.swift
Last active June 9, 2021 18:17
UILabel extension to truncate & highlight a keyword in a large sentence, add ellipsis to left & right of label
extension UILabel {
private var attributes: [NSAttributedString.Key: Any] {
return [.font: self.font ?? UIFont.systemFont(ofSize: 15)]
}
private var highlightAttributes: [NSAttributedString.Key: Any] {
return [.backgroundColor: UIColor.lightGray.withAlphaComponent(0.2), .foregroundColor: UIColor.red]
}
@Catherine-K-George
Catherine-K-George / UILabel+Extensions.swift
Created June 6, 2021 09:49
UILabel extension with ReadMore/ ReadLess action
import UIKit
enum TrailingContent {
case readmore
case readless
var text: String {
switch self {
case .readmore: return "...Read More"
case .readless: return " Read Less"
@Catherine-K-George
Catherine-K-George / AWSS3Uploader.swift
Last active August 6, 2023 08:47
File upload to AWS S3 with pre-signed URL iOS/Swift 5
import AWSS3
class AWSS3Uploader {
/// Creates a upload request for uploading the specified file to a presigned remote URL
///
/// - Parameters:
/// - fileURL: The URL of the file to upload.
/// - remoteURL: The presigned URL
/// - completion: The completion handler to call when the upload request is complete.