/// Classes whose initializers actually create derived classes | |
protocol FactoryInitializable { | |
/// The type of the least-derived class declared to be FactoryInitializable. | |
/// | |
/// - Warning: Do not define this in your FactoryInitializable type! | |
associatedtype FactoryBase: AnyObject, FactoryInitializable = Self | |
// This associatedtype is a trick that captures `Self` at the point where | |
// `FactoryInitializable` enters a class hierarchy; in other contexts, `Self` | |
// refers to the most-derived type. | |
} |
Simulation Begin | |
! We will use this as input to Normal() below ; | |
Integer seed; | |
! Utility method for logging messages along with the current simulation | |
time ; | |
Procedure log(message); Text message; Begin | |
OutFix(Time, 2, 0); | |
OutText(": " & message); | |
OutImage; |
(declaim (ftype (function (fixnum function) ) triples)) | |
(time | |
(defun triples (n func) | |
(declare (optimize (speed 3) (debug 0) (safety 0))) | |
(declare (type function func) | |
(type fixnum n)) | |
(let ((count 0)) | |
(declare (type fixnum count)) | |
(loop for z fixnum from 1 do | |
(loop for x fixnum from 1 to z do |
//: Playground - noun: a place where people can play | |
import UIKit | |
/* Scroll to the bottom for examples */ | |
typealias WritableObjectKeyPath<O: NSObject, V: Equatable> = (object: O, keyPath: WritableKeyPath<O, V>) | |
typealias ReadOnlyObjectKeyPath<O: NSObject, V: Equatable> = (object: O, keyPath: KeyPath<O, V>) | |
func bind<O: NSObject, O2: NSObject, V: Equatable>(source: ReadOnlyObjectKeyPath<O, V>, to target: WritableObjectKeyPath<O2, V>) -> NSKeyValueObservation? |
//: Playground - noun: a place where people can play | |
import UIKit | |
/* Scroll to the bottom for examples */ | |
typealias WritableObjectKeyPath<O: NSObject, V: Equatable> = (object: O, keyPath: WritableKeyPath<O, V>) | |
typealias ReadOnlyObjectKeyPath<O: NSObject, V: Equatable> = (object: O, keyPath: KeyPath<O, V>) | |
func bind<O: NSObject, O2: NSObject, V: Equatable>(source: ReadOnlyObjectKeyPath<O, V>, to target: WritableObjectKeyPath<O2, V>) -> NSKeyValueObservation? |
The libdispatch is one of the most misused API due to the way it was presented to us when it was introduced and for many years after that, and due to the confusing documentation and API. This page is a compilation of important things to know if you're going to use this library. Many references are available at the end of this document pointing to comments from Apple's very own libdispatch maintainer (Pierre Habouzit).
My take-aways are:
-
You should create very few, long-lived, well-defined queues. These queues should be seen as execution contexts in your program (gui, background work, ...) that benefit from executing in parallel. An important thing to note is that if these queues are all active at once, you will get as many threads running. In most apps, you probably do not need to create more than 3 or 4 queues.
-
Go serial first, and as you find performance bottle necks, measure why, and if concurrency helps, apply with care, always validating under system pressure. Reuse
#! /usr/bin/env ruby | |
# NOTE: Requires Ruby 2.1 or greater. | |
# This script can be used to parse and dump the information from | |
# the 'html/contact_info.htm' file in a Facebook user data ZIP download. | |
# | |
# It prints all cell phone call + SMS message + MMS records, plus a summary of each. | |
# | |
# It also dumps all of the records into CSV files inside a 'CSV' folder, that is created |