Skip to content

Instantly share code, notes, and snippets.

View glowcap's full-sized avatar
🍛
お腹がすいた

Daymein Gregorio glowcap

🍛
お腹がすいた
View GitHub Profile
@glowcap
glowcap / AnalyticsRequirements.swift
Last active February 24, 2025 13:04
AIChat app analytic events setup
// Basing Modules/Logs, Analytics, Crashlytics/Adding Events (1/4)
/*
The idea here is to eliminate a majority of the duplication while keeping the same event output.
The final result being what is shown below
*/
// MARK: Analytic Events
enum Event: LoggableEvent, EventEnum {
@glowcap
glowcap / USStateAndTerritory.swift
Last active February 12, 2023 23:39
Swift State and Territory enums
/// includes USStateAndTerritory enum and USState enum
/// required for retreiving the full name from the enum cases
extension String {
/// Splits a camelCase string and capitalizes each word
/// - Returns: self split into words and capitalized
/// - Note: In its current configuration, it does not
/// follow proper title formatting.
@glowcap
glowcap / emailValidation.swift
Last active February 12, 2023 15:38
Swift 5.7 Email Validation
/// Validation based on RFC 5321, but omitting some
/// cases to conform with email-as-username authentication
/// add those cases as needed
import Foundation
extension String {
var validEmail: Bool {
if exceedsEmailLength() { return false }
if containsDoubleDots() { return false }
@glowcap
glowcap / ContinueExample.swift
Created January 18, 2018 04:26
Example of using continue in a loop
import UIKit
let puzzleInput = "great minds think alike"
var puzzleOutput = ""
let charactersToRemove: [Character] = ["a", "e", "i", "o", "u", " "]
/// When using `continue` in an `if` statement (or switch) of a loop, the
/// loop immediately goes to the next iteration of the loop with completing
/// the rest of the current loop iteration.
@glowcap
glowcap / DeviceDetector.swift
Last active January 24, 2018 00:12
Check which device is being used
import UIKit
public enum Model : String {
case simulator = "simulator/sandbox",
iPod1 = "iPod 1",
iPod2 = "iPod 2",
iPod3 = "iPod 3",
iPod4 = "iPod 4",
iPod5 = "iPod 5",
iPad2 = "iPad 2",
@glowcap
glowcap / iOS11iPhoneXCheck.swift
Last active November 6, 2017 23:17
iOS11 iPhoneX if
if #available(iOS 11, *) {
// if iOS11 parameters isn't enough
if UIDevice().type == .iPhoneX {
// iPhone X parameters
} else {
// iOS11 parameters
}
} else {
// original parameters
}
@glowcap
glowcap / HandlingOptionals.swift
Created September 26, 2017 00:41
Handling Optionals in Swift
//: Interview Question - Handling optionals
import UIKit
// There are four common ways to handle optionals
// in Swift
// if let
var myString: String?
myString = "myString"
@glowcap
glowcap / FilterMapReduce.swift
Last active September 26, 2017 00:39
//: Filter, Map, Reduce - Interview question
//: Filter, Map, Reduce - Interview question
import UIKit
// Our Skate shop just got a big order of wheels delivered
// We enter the wheels into the system like this:
struct Wheel {
let brand: String
let color: String
@glowcap
glowcap / ForbiddenWords-Eng.swift
Created August 16, 2017 07:00
Array of English bad words
//
// ForbiddenWords-Eng.swift
// Used for filtering user input
// Please forgive the objectionable language. m(_ _)m
//
// Created by daymein gregorio on 2017/08/16.
// Copyright © 2017 daymein gregorio. All rights reserved.
//
import Foundation
@glowcap
glowcap / afterDelay.swift
Last active August 16, 2017 07:07
Swift3 trigger method after delay
// I always forget how to write this stupid thing
// now I just have to remember I put it here
/// This function calls a closure after a delay.
/// Use it when you want to wait for a certain amount of
/// time before letting an action run
///
/// - Parameters:
/// - delay: seconds you want to wait
/// - closure: the function you want to run after the delay