Skip to content

Instantly share code, notes, and snippets.

View theevo's full-sized avatar

Theo Vora theevo

  • NYC
View GitHub Profile
// Type Extensions
extension Array { // concrete type
var isNotEmpty: Bool {
isEmpty == false
}
}
let goingToWWDC = ["Bryce", "Alex"]
//print(goingToWWDC.isNotEmpty)
@theevo
theevo / WordCount.swift
Created December 8, 2023 01:03
Interview practice using Swift
import Foundation
// Write a function in swift that takes a sentence as input and returns the count of each word in the sentence. Ignore punctuation and consider words as case-insensitive. For example, given the input "Hello, world! hello", the function should return ["hello": 2, "world": 1]
func wordCount(str: String) -> [String: Int] {
// if empty input string, return empty dict
guard !str.isEmpty else {
return [:]
}
@theevo
theevo / SF Bold.swift
Created March 11, 2023 07:14
why does preferredFontDescriptor return an optional?
var countdownTimerLabel: UILabel = UILabel()
countdownTimerLabel.font = boldFont() ?? UIFont.systemFont(ofSize: 75, weight: .regular)
private func boldFont() -> UIFont? {
guard let descriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .largeTitle).withSymbolicTraits(.traitBold) else { return nil }
return UIFont(descriptor: descriptor, size: 75)
}
@theevo
theevo / Timer.swift
Created January 19, 2023 11:13
This repeating timer fires off 3 times and displays the fire time in Date.ISO8601FormatStyle
import Foundation
var limit = 3
let timer2 = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { timer in
limit -= 1
let isoFormat = Date.ISO8601FormatStyle(timeZone: TimeZone.current)
.time(includingFractionalSeconds: true)
@theevo
theevo / config
Created February 6, 2022 19:30
My ssh config
Host github.com
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
Host bitbucket.org
HostName bitbucket.org
AddKeysToAgent yes
@theevo
theevo / deinit order.swift
Created September 20, 2021 21:26
A always gets deinit before B
class A {
var b: B
init(b: B) {
self.b = b
}
deinit {
print(" Destroying A")
}
import Foundation
/*
* Complete the 'cardPackets' function below.
*
* The function is expected to return an INTEGER.
* The function accepts INTEGER_ARRAY cardTypes as parameter.
*/
func cardPackets(cardTypes: [Int]) -> Int {
if true, true {
print("Both are true")
}
if true, false {
print("")
} else {
print("One of these is false")
}
extension String {
var length: Int {
return count
}
subscript (i: Int) -> String {
return self[i ..< i + 1]
}
import Foundation
class Solution {
static let openingChars = "({["
static let closingChars = ")}]"
var stack: [String.Element] = []
private func pushClosingChar(_ char: String.Element) {