Skip to content

Instantly share code, notes, and snippets.

// TODO: insert guards to use open-source version of random() if necessary
func random(x: Int) -> Int {
return Int(arc4random_uniform(UInt32(endBoundary)))
}
extension CollectionType {
/// create a lazy succession of randomly ordered indices
///
@ilyannn
ilyannn / bangbang.md
Last active June 29, 2017 17:49 — forked from erica/bangbang.md

Instead of

assert(!array.isEmpty, "Array guaranteed to be non-empty because...")
let lastItem = array.last!

guard !array.isEmpty 
    else { fatalError("Array guaranteed to be non-empty because...") }

// ... etc ...
@ilyannn
ilyannn / fold.py
Last active August 29, 2019 15:28
Almost one-liner fold
def fold(s, p = 0):
for i in [i+1 for (i, c), n in zip(enumerate(s), s[1:]+' ') if c != n]: p = print(s[p], i-p, sep="", end="") or i