Skip to content

Instantly share code, notes, and snippets.

Erica Sadun erica

Block or report user

Report or block erica

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View split.swift
let string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi enim lacus, ullamcorper in gravida a, semper id dolor. Mauris quis metus id"
extension String {
public func split(
maxSplit: Int = .max,
allowEmptySlices: Bool = false,
@noescape isSeparator: ((Character) throws -> Bool)) rethrows -> [String] {
return try self.characters.split(
View gist:8805407
0. Read the <link>FAQ</link>. Other *mandatory* reading follows at the bottom of these rules.
1. Google first, ask second. You must work through the Rubber Duck process <i>before</i> asking questions in-channel.
2. This is a volunteer-staffed channel. The time of the volunteers is worth at *least* as much as your time. We are not your employees or your servants. Clean your own room, do your own homework, write your own code, and don't forget to say "Thank you" for the help.
3. The phrase "doesn't work" isn't allowed. Prepare to explain the problem without links to Stack Overflow.
4. Show your code. We don't care about your NDAs. If you don't want to show your code, go pay a consultant. We may ask you to create a minimal project that demonstrates your issue. Save time by doing so before entering the channel.
erica / gist:481a34bc2a6f838dcdbe
Created Jun 23, 2014
Xcode seems to hate this
View gist:481a34bc2a6f838dcdbe
import Foundation
struct BagGenerator<T:Hashable> : Generator
typealias Element = (T, Int, Int)
var count = 0
var _backingGenerator : DictionaryGenerator<T, Int>
init(_ backingDictionary : Dictionary<T, Int>) {
_backingGenerator = backingDictionary.generate()
View gist:9e573199411651d2825f
// Bag.swift
// CmdLineTest
// Created by Erica Sadun on 6/23/14.
// Copyright (c) 2014 Erica Sadun. All rights reserved.
import Foundation
View gist:06d7e44f4f834757dc36
// explore.swift
// CmdLineTest
// Created by Erica Sadun on 6/25/14.
// Copyright (c) 2014 Erica Sadun. All rights reserved.
import Foundation
View gist:6faee76937ab8cb76e5a
import Cocoa
// See
extension Array {
var first : Element? {return self.count > 0 ? self[0] : nil}
var last : Element? {return self.count > 0 ? self[self.count - 1] : nil}
var random : Element? {return self.count > 0 ? self[Int(arc4random_uniform(UInt32(self.count)))] : nil}
View gist:03370461300bfaa6450e
protocol AbsoluteValuable
protocol ArrayBound
protocol ArrayBufferType
protocol ArrayLiteralConvertible
protocol ArrayType
protocol BidirectionalIndex
protocol BitwiseOperations
protocol CVarArg
protocol CharacterLiteralConvertible
protocol Collection
View gist:39c70651a322f8408afa
#! /bin/sh
# All credit to @mikeash
echo "import Cocoa\n:print_decl $1" | /Applications/ -integrated-repl | open -f
View gist:864138585c7ea43ed20b
let fd = open("/tmp/scratch.txt", O_WRONLY|O_CREAT, 0o666)
if fd < 0 {
perror("could not open /tmp/scratch.txt")
} else {
let text = "Hello World\n"
write(fd, text, strlen(text))
View gist:811977c22b5559d941cb
let fname = "/tmp/scratch.txt"
let fptr = fopen(fname, "w")
if (fptr == nil) {
let localErrno = errno
println("Unable to open \(fname): \(strerror(localErrno))")
} else {
let text = "Hello World\n"
let bytesWritten = fwrite(text, UInt(sizeof(Byte)), strlen(text), fptr)
println("Wrote \(bytesWritten) bytes")
You can’t perform that action at this time.