Skip to content

Instantly share code, notes, and snippets.

View GrantJEmerson's full-sized avatar

Grant Emerson GrantJEmerson

View GitHub Profile
@GrantJEmerson
GrantJEmerson / RemoveOrPop.swift
Created November 24, 2019 17:30
Remove or Pop - SwiftMoji Entry #28
var 📧inbox = [
"Don't miss this weekend's sale at Bob's Pizzeria!",
"Urgent: Production Database Backup Failed",
"Wednesday Developer Meetup Reminder"
]
while let 📧 = 📧inbox.popLast() {
print(📧)
}
@GrantJEmerson
GrantJEmerson / StringsToBeWritten.swift
Created November 24, 2019 17:26
Strings to Be Written - SwiftMoji Entry #27
import Foundation
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let url = documentsDirectory.appendingPathComponent("Closet Contents").appendingPathExtension("txt")
var closet = "👖x2 👕x5 👔x3 👟x2 👞x2"
do {
try closet.write(to: url, atomically: true, encoding: .utf8)
} catch {
@GrantJEmerson
GrantJEmerson / PowerfulPredicates.swift
Created November 24, 2019 17:20
Powerful Predicates - SwiftMoji Entry #26
import Foundation
@objcMembers class Craft: NSObject {
let name: String
let maxAltitude: Int
let maxSpeed: Int
init(name: String, maxAltitude: Int, maxSpeed: Int) {
self.name = name
self.maxAltitude = maxAltitude
@GrantJEmerson
GrantJEmerson / MergingFoodWithThought.swift
Created November 24, 2019 17:17
Merging Food With Thought - SwiftMoji Entry #25
let saturdayFoodLog = ["🍎": 2, "🥗": 2, "🥚": 3, "🥜": 20, "🍪": 2]
let sundayFoodLog = ["🥚": 1, "🥗": 1, "🍎": 1, "🍪": 1, "🌭": 2, "🥩": 1]
let weekendFoodLog = saturdayFoodLog.merging(sundayFoodLog) { $0 + $1 }
print(weekendFoodLog) // ["🥩": 1, "🥚": 4, "🥗": 3, "🍎": 3, "🥜": 20, "🌭": 2, "🍪": 3]
@GrantJEmerson
GrantJEmerson / LiterallyAmazing.swift
Created November 24, 2019 17:12
Literally Amazing - SwiftMoji Entry #24
struct 👤: Identifiable {
static var peopleCount = 0
let name: String
let height: Float
var id: String = {
Self.peopleCount += 1
return "\(#function) \(Self.peopleCount)"
}()
@GrantJEmerson
GrantJEmerson / IntoTheBitwiseSpectrum.swift
Created November 24, 2019 17:09
Into the Bitwise Spectrum - SwiftMoji Entry #23
import Foundation
typealias HexadecimalColor = UInt32
let 🎨: HexadecimalColor = 0xFF872C // RGB(255, 135, 44)
let 🔴 = (🎨 & 0xFF0000) >> 16 // 255
let 💚 = (🎨 & 0x00FF00) >> 8 // 135
let 🔵 = 🎨 & 0x0000FF // 44
@GrantJEmerson
GrantJEmerson / IndexingIntoRandomness.swift
Created November 24, 2019 17:06
Indexing Into Randomness - SwiftMoji Entry #22
import Foundation
let buffet = ["🍕", "🍔", "🌭", "🥗", "🌯", "🥘"]
let dinner = buffet.randomElement()!
print("Tonight I will eat \(dinner).") // Tonight I will eat 🍕.
@GrantJEmerson
GrantJEmerson / GreatestOrBiggest.swift
Created November 24, 2019 16:51
Greatest or Biggest - SwiftMoji Entry #21
let 🚀Velocities = [700.55, 500.3, 1015.0, -50.0, -2000.25]
let maxVelocity = 🚀Velocities.reduce(0, Double.maximumMagnitude)
print("\(maxVelocity) mph") // -2000.25 mph
@GrantJEmerson
GrantJEmerson / BinaryToDecimal.swift
Last active December 1, 2020 22:29
Binary To Decimal - SwiftMoji Entry #20
let binaryMessage = "101001011001000101111011110101011"
let 📞🔢 = Int(binaryMessage, radix: 2)!
print(📞🔢) // 5555550123
@GrantJEmerson
GrantJEmerson / BattleOfTheUnits.swift
Created November 24, 2019 16:24
Battle of the Units - SwiftMoji Entry #19
import Foundation
let 🇺🇸🧊 = Measurement(value: 13, unit: UnitTemperature.fahrenheit)
let 🇬🇧🧊 = 🇺🇸🧊.converted(to: UnitTemperature.celsius)
print("It's \(Int(🇺🇸🧊.value))ºF or \(Int(🇬🇧🧊.value))ºC outside! 🥶")
// It's 13ºF or -10ºC outside! 🥶