Skip to content

Instantly share code, notes, and snippets.

View albtsantos's full-sized avatar
👽

Alberto albtsantos

👽
  • AssemblyAI
View GitHub Profile

Keybase proof

I hereby claim:

  • I am albtsantos on github.
  • I am albt (https://keybase.io/albt) on keybase.
  • I have a public key ASC9hw9Lb7_Ve64vfXwteBY_aWmAr2Oyv6fBZhp2m0tz-Qo

To claim this, I am signing this object:

@albtsantos
albtsantos / minus
Created August 3, 2014 02:43
Minus infix for Swift strings
@infix func - (left: String, right: String) -> String {
var finalString = left
if left.hasSuffix(right) {
// the workaround to the compiler error is to cast the String to NSString before the substringToIndex method
var index = countElements(left) - countElements(right)
finalString = (left as NSString).substringToIndex(index)
}
return finalString
@albtsantos
albtsantos / decrement
Created August 2, 2014 22:09
Decrement operator for Swift arrays
@assignment @prefix func -- <T> (inout a: [T]) -> [T] {
if a.count > 0 {
a.removeLast()
}
return a
}
var names: [String] = ["iPhone", "iPad", "iPod", "Nexus"]
--names
@albtsantos
albtsantos / multiplicator
Created August 2, 2014 22:00
Multiplicator infix for Swift strings
@infix func * (string: String, multiplicator: Int) -> String {
if multiplicator < 0 {
return ""
}
var finalString: String = ""
for i in 0..<multiplicator {
finalString += string
}