Skip to content

Instantly share code, notes, and snippets.

View mmar's full-sized avatar
🐈‍⬛

Matusalem Marques mmar

🐈‍⬛
View GitHub Profile
@mmar
mmar / for_case_let.swift
Created February 3, 2023 12:33
Swift optional pattern matching in a for-in loop
// Source: https://docs.swift.org/swift-book/ReferenceManual/Patterns.html#grammar_optional-pattern
let arrayOfOptionalInts: [Int?] = [nil, 2, 3, nil, 5]
for case let number? in arrayOfOptionalInts {
print("Found a \(number)")
}
@mmar
mmar / swift.svg
Created December 29, 2020 22:49
Swift Logo
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mmar
mmar / geocoding.swift
Last active December 29, 2020 22:38
Geocoding in Xcode playgrounds
import MapKit
import PlaygroundSupport
let mapView = MKMapView()
PlaygroundPage.current.liveView = mapView
CLGeocoder().geocodeAddressString("1 Apple Park Way, Cupertino, CA") {
(places, _) in
guard let places = places?.map(MKPlacemark.init) else { return }
mapView.showAnnotations(places, animated: true)
@mmar
mmar / iOS 12 supported timezones.csv
Created March 13, 2019 21:03
iOS 12 supported timezones
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
@mmar
mmar / String+guessedNameFromEmail.swift
Created November 22, 2018 14:52
Try to guess names from email addresses in Swift
import Foundation
extension String {
var guessedNameFromEmail: String? {
return self.split(separator: "@").first?.split(separator: ".").map { $0.capitalized(with: Locale.autoupdatingCurrent) }.joined(separator: " ")
}
}
DEVICE TYPE PRODUCT NAME
iPhone1,1 iPhone
iPhone1,2 iPhone 3G
iPhone2,1 iPhone 3GS
iPhone3,1 iPhone 4 (GSM)
iPhone3,2 iPhone 4 (GSM, Revision A)
iPhone3,3 iPhone 4 (CDMA)
iPhone4,1 iPhone 4S
iPhone5,1 iPhone 5 (A1428)
iPhone5,2 iPhone 5 (A1429)
@mmar
mmar / git-backup
Created July 23, 2018 12:38
Backup git repository to a single file using `git bundle`. You can put this in your path and call it as `git backup`.
#!/bin/sh
git bundle create ~/Backups/`basename $PWD`.git --all
localeIdentifier Description
eu Basque
hr_BA Croatian (Bosnia & Herzegovina)
en_CM English (Cameroon)
en_BI English (Burundi)
en_AE English (United Arab Emirates)
rw_RW Kinyarwanda (Rwanda)
ast Asturian
en_SZ English (Eswatini)
he_IL Hebrew (Israel)
@mmar
mmar / TriangularNumbers.swift
Created November 10, 2017 15:51
Triangular numbers.
let triangularNumbers = sequence(state: (0,0)) { (state: inout (Int,Int)) -> Int in
state = (state.0 + 1, state.1 + state.0 + 1 )
return state.1
}
@mmar
mmar / PascalsTriangle.swift
Last active December 28, 2020 22:32
Pascal's Triangle (Swift)
let pascalsTriangle = sequence(first: [1]) {
zip([0] + $0, $0 + [0]).map(+)
}