Skip to content

Instantly share code, notes, and snippets.

import Foundation
let timer = DispatchSource.makeTimerSource(queue: .main)
timer.scheduleRepeating(wallDeadline: .now(), interval: .milliseconds(100), leeway: .milliseconds(100))
var count = 0
timer.setEventHandler(handler: {
count += 1
print("hello \(count)")
if count >= 10 {
exit(0)

Keybase proof

I hereby claim:

  • I am mikeash on github.
  • I am mikeash (https://keybase.io/mikeash) on keybase.
  • I have a public key ASCv3cdmBXff1Ml-lYYQ-qcFZBVjSttjxmndX-XLa-Lb8wo

To claim this, I am signing this object:

// $ swift -O test.swift
// native: 41.0220462589987 seconds
// NSMutableSet: 0.0347055729998829 seconds
// native single set: 0.00811006900039501 seconds
// NSMutableSet single set: 0.0452864170001703 seconds
import Foundation
var a: [Int: [Int: Set<Int>]] = [:]
var b: [Int: [Int: NSMutableSet]] = [:]
// from https://github.com/swansontec/map-macro/blob/master/map.h
/*
* Copyright (C) 2012 William Swanson
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
function HTMLEscape(s)
{
return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}
function CommentPreview()
{
$("#commentPreviewLabelArea").html("<b>Loading comment preview....</b><p>");
$.post("/commentsubmit.py", $("#commentForm").serialize() + "&preview=true",
function(data) {
func responderForType<T>(from: UIResponder) -> T? {
var current = from
while let next = current.nextResponder() {
if let result = next as? T { return result }
current = next
}
return nil
}
import Darwin
struct S {
var whatever: AnyObject? = nil
mutating func stuff() {
withUnsafePointer(&whatever, {
for offset in 0.stride(to: 128, by: sizeof(AnyObject.self)) {
let ptr = UnsafePointer<UInt8>($0) - offset
if malloc_size(ptr) > 0 {
#!/usr/bin/swift
import Foundation
class ValueWithDestructor<T> {
var value: T
let destructor: T -> Void
init(value: T, destructor: T -> Void) {
self.value = value
import Foundation
struct NumberOrObjectButNotNSNumberObjects {
private var storage: AnyObject? = nil
var object: AnyObject? {
get {
return (storage is NSNumber) ? nil : storage
}
set {
import Foundation
protocol Stringable {
var string: String { get }
}
extension String: Stringable {
var string: String {
return self
}
}
extension Dictionary where Key: Stringable {