Skip to content

Instantly share code, notes, and snippets.

@Yorzic
Yorzic / index.js
Last active September 23, 2020 04:27
Custom Firebase functions region
exports.myStorageFunction = functions
.region('australia-southeast1')
.storage
.object()
.onFinalize((object) => {
// ...
});
// Reference: https://stackoverflow.com/questions/43569595/firebase-deploy-to-custom-region-eu-central1
@Yorzic
Yorzic / MainViewController.swift
Created September 4, 2020 06:03
Detect environment
override func viewDidLoad() {
super.viewDidLoad()
#if DEVELOPMENT
print("Development environment.")
#elseif PRODUCTION
print("Production environment.")
#else
print("Unknown environment.")
#endif
@Yorzic
Yorzic / StringExtension.swift
Created August 9, 2020 15:59
What's the gist physicist
import CryptoKit
extension String {
var md5: String {
let digest = Insecure.MD5.hash(data: self.data(using: .utf8) ?? Data())
return digest.map {
String(format: "%02hhx", $0)
}.joined()
}
@Yorzic
Yorzic / TextFieldWithLabelCell.swift
Last active June 18, 2020 05:06
UITableViewCell with limit on the number of characters
//
// TextFieldWithLabelCell.swift
// Apy
//
// Created by Artur Daylidonis on 20/5/20.
// Copyright © 2020 Artur Daylidonis. All rights reserved.
//
import UIKit
@Yorzic
Yorzic / ViewController.swift
Created May 29, 2020 16:26
Example TableViewController with UIDocumentPicker that handles CSV Files
//
// ViewController.swift
// HandleCSVFile
//
// Created by Artur Daylidonis on 18/5/20.
// Copyright © 2020 Artur Daylidonis. All rights reserved.
//
import UIKit
import MobileCoreServices
@Yorzic
Yorzic / TableViewController.swift
Created May 29, 2020 16:19
Call handleCSVFile method from documentPicker didPickDocumentsAt method in iOS
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let myURL = urls.first else {
return
}
print("import result : \(myURL)")
if let data = handleCSVFile(url: myURL) {
cells = data
tableView.reloadData()
}
}
@Yorzic
Yorzic / Extensions.swift
Created May 29, 2020 16:17
Extensions for handling CSV Files in iOS
extension UIViewController {
func handleCSVFile(url: URL) -> [[String]]? {
if let data = try? String(contentsOf: url) {
var result: [[String]] = []
let rows = data.components(separatedBy: "\r\n")
for row in rows {
let columns = row.components(separatedBy: ",")
var cells: [String] = []
for item in columns {
@Yorzic
Yorzic / TableViewController.swift
Created May 29, 2020 16:13
Trigger UIDocumentPickerViewController
func selectFile() {
let importMenu = UIDocumentPickerViewController(documentTypes: [(kUTTypeCommaSeparatedText as String)], in: .import)
importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)
}
@Yorzic
Yorzic / TableViewController.swift
Last active May 29, 2020 16:06
Adhering to UIDocumentPickerViewController
public func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
guard let myURL = urls.first else {
return
}
print("import result : \(myURL)")
}
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
print("view was cancelled")
dismiss(animated: true, completion: nil)
@Yorzic
Yorzic / TableViewController.swift
Last active May 29, 2020 15:57
Include custom cell with xib
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "DataCell", bundle: nil), forCellReuseIdentifier: "DataCell")
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DataCell", for: indexPath) as! DataCell
return cell