Skip to content

Instantly share code, notes, and snippets.

@Cosmo
Last active July 30, 2019 06:28
Show Gist options
  • Save Cosmo/ad8a4bd7d74d3ed87bc986f88a9b3743 to your computer and use it in GitHub Desktop.
Save Cosmo/ad8a4bd7d74d3ed87bc986f88a9b3743 to your computer and use it in GitHub Desktop.
Different ways to say "moin" (hello in german) in Swift.
import Foundation
// July 1, 2019
print([109, 111, 105, 110].map { String(UnicodeScalar($0)) }.joined())
// July 2, 2019
var hex: UInt32 = 0x6E696F6D
let data = Data(bytes: &hex, count: MemoryLayout<UInt32>.size)
String(data: data, encoding: String.Encoding.ascii)
// July 3, 2019
import PeriodicTable
(Elements.molybdenum.symbolValue + Elements.indium.symbolValue).lowercased()
// July 4, 2019
print("npjo".map { String(UnicodeScalar(($0.asciiValue ?? 0).advanced(by: -1))) }.joined())
// July 5, 2019
var str = "cosmo sagt: einen guten morgen euch allen"
.replacingOccurrences(of: "[a-h|j-l|p-z|:|\\s]*", with: "", options: .regularExpression)
print(str[str.index(str.startIndex, offsetBy: 1)..<str.index(str.startIndex, offsetBy: 5)])
// July 6, 2019
var parts = Array("nimo")
repeat { parts.shuffle() } while Data(String(parts).utf8).base64EncodedString() != "bW9pbg=="
print(String(parts))
// July 7, 2019
print(["monstrous", "objectionable", "insipiring", "nonsense"].reduce("") { $0 + $1.prefix(1) })
// July 8, 2019
let symbols: [Character] = ["πŸ€‘", "πŸ‘Œ", "πŸ“₯", "🀒"]
print(symbols.reduce("") { $0 + ($1.unicodeScalars.first?.properties.name?.prefix(1))! }.lowercased())
// July 9, 2019
"bier".replacingOccurrences(of: "bier", with: "moin")
// July 10, 2019
var str = NSURLCredentialStorageRemoveSynchronizableCredentials
.lowercased()
.replacingOccurrences(of: "[a-h|j-l|p-z]*", with: "", options: .regularExpression)
str.removeFirst(1)
str.removeLast(7)
print(String(str.reversed()))
// July 11, 2019
print([["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]].map { $0.count }.reduce("", { $0 + String(UnicodeScalar($1)!) }))
// July 12, 2019
print(([Int(1), Int(2), Int(3), Int(4)].map({
if $0 == 1 { return $0 << 6 + $0 << 5 + 13 }
else if $0 == 2 { return $0 * 3 + 105 }
else if $0 == 3 { return $0 * 35 }
else { return $0 / 2 * 55 }
}) as [Int]).reduce("", { $0 + String(UnicodeScalar($1)!) }))
// July 13, 2019
String("niom".reversed())
// July 14, 2019
var array = [5]
array.insert(array.first! - 1, at: 0)
array.insert(array.first! + 2, at: 1)
array.insert(0, at: 2)
print(array.reduce("", { $0 + String(UnicodeScalar($1 + 105)!) }))
// July 15, 2019
var str = "montag"
str = String(str.prefix(3))
str.insert("i", at: str.index(str.startIndex, offsetBy: 2))
print(str)
// July 16, 2019 β€” Contributed by Marius Landwehr @mRs-
"πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦".unicodeScalars
.reduce([UnicodeScalar]()) { scalars, char in
var s = scalars
s.append(char)
return s
}
.enumerated()
.compactMap({ (offset, element) -> UnicodeScalar? in
switch offset {
case 0:
return UnicodeScalar(element.value - UInt32(127_995))
case 2:
return UnicodeScalar(element.value - UInt32(127_994))
case 4:
return UnicodeScalar(element.value - UInt32(127_998))
case 6:
return UnicodeScalar(element.value - UInt32(127_992))
default:
return nil
}
})
.reduce("") { $0 + String(Character.init($1)) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment