Skip to content

Instantly share code, notes, and snippets.

View lilyball's full-sized avatar

Lily Ballard lilyball

View GitHub Profile
func update(_ arg: inout String) {
arg = "UPDATED \(arg)"
}
let mainQueue = DispatchQueue.init(label: "mainQueue", qos: .userInitiated, attributes: [], autoreleaseFrequency: .workItem, target: nil)
let workerQueue = DispatchQueue.init(label: "workerQueue", qos: .userInitiated, attributes: [.concurrent], autoreleaseFrequency: .workItem, target: nil)
let systemQueue = DispatchQueue.init(label: "systemQueue", qos: .userInitiated, attributes: [], autoreleaseFrequency: .workItem, target: nil)
print("Sample Started")
extension Date {
var asTimespec: timespec {
let delta = timeIntervalSince1970
let seconds = delta.rounded(.down)
let ns = (delta - seconds) * 1_000_000_000
return timespec(tv_sec: Int(seconds), tv_nsec: Int(ns))
}
}
let dict = UserDefaults.standard.dictionary(forKey: String(key)) ?? [:]
var result = Dictionary<Int,Bool>(minimumCapacity: dict.count)
for (key, value) in dict {
guard let intKey = key as? Int,
let boolValue = value as? Bool
else { continue }
result[intKey] = boolValue
}
return result
class Root {}
extension Root {
class Sub {}
}
extension Root.Sub {
func foo() { print("foo!") }
}
# ...
command script import ~/path/to/viewControllers.py
# ...
var LIBIRC_ERR_ACCEPT: Swift.Int32 {
get {}
}
var LIBIRC_ERR_CLOSED: Swift.Int32 {
get {}
}
var LIBIRC_ERR_CONNECT: Swift.Int32 {
get {}
}
var LIBIRC_ERR_CONNECT_SSL_FAILED: Swift.Int32 {
@lilyball
lilyball / DefaultKeyBinding.dict
Last active October 7, 2016 23:44
Put this in ~/Library/KeyBindings
{
/* basic text manipulation */
"^u" = "deleteToBeginningOfParagraph:";
/* Modifier keys: start with C-m */
"^m" = {
"^e" = ("insertText:", "\U21A9"); /* C-e return */
"e" = ("insertText:", "\U2305"); /* e enter */
"^t" = ("insertText:", "\U21E5"); /* C-t tab */
"t" = ("insertText:", "\U21E4"); /* t backtab */
@lilyball
lilyball / reviewable_bindings.json
Created October 7, 2016 22:52
Reviewable bindings
[
["f", "Show next/latest diffs", "setProposedRevRanges()"],
[null, "Next unreviewed file", "nextUnreviewedFile()"],
[null, "Previous unreviewed file", "prevUnreviewedFile()"],
["n", "Next personally unreviewed file", "nextPersonallyUnreviewedFile()"],
["p", "Previous personally unreviewed file", "prevPersonallyUnreviewedFile()"],
["shift+n", "Next changed file", "nextChangedFile()"],
["shift+p", "Previous changed file", "prevChangedFile()"],
[null, "Next visible file", "nextVisibleFile()"],
import Foundation
extension Collection {
subscript(first: Index, second: Index, rest: Index...) -> [Iterator.Element] {
var results: [Iterator.Element] = []
results.reserveCapacity(rest.count + 2)
results.append(self[first])
results.append(self[second])
results.append(contentsOf: rest.lazy.map({ self[$0] }))
return results
import Darwin.Mach.mach_time
/// Benchmarks a function and prints the results to stdout.
func benchmark<T,R>(label: String, @noescape setup: () -> T, @noescape f: T -> R) {
// get a ballpark time estimate
let estimateInput = setup()
let estimateStart = get_current_ns()
let _ = blackBox(f, args: estimateInput)
let estimateEnd = get_current_ns()
let estimate = estimateEnd - estimateStart