This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This sketches a script that will sample images from an AVAsset at a | |
// new framerate. This might be used to transcode a movie or create an | |
// animated GIF. | |
import AppKit | |
import AVFoundation | |
import CoreMedia | |
let FPS = 12 // The target framerate for the new movie. | |
let frameDuration = CMTimeMake(1, Int32(FPS)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVFoundation | |
import Foundation | |
// The maximum number of audio buffers in flight. Setting to two allows one | |
// buffer to be played while the next is being written. | |
private let kInFlightAudioBuffers: Int = 2 | |
// The number of audio samples per buffer. A lower value reduces latency for | |
// changes but requires more processing but increases the risk of being unable | |
// to fill the buffers in time. A setting of 1024 represents about 23ms of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: @schwa figured this out, but I'm claiming some of the credit for asking the question. | |
// See https://gist.github.com/schwa/ecd5f8c154e60fcb0f58 for the original solution. | |
// Playground - noun: a place where people can play | |
import Foundation | |
// Implementation (repeat as needed for number of parameters). | |
func unwrap<T1, T2>(p1: T1?, p2: T2?) -> (T1, T2)? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton { | |
class var sharedInstance: Singleton { | |
struct Static { | |
static var token: dispatch_once_t = 0 | |
static var instance: Singleton! | |
} | |
dispatch_once(&Static.token) { | |
Static.instance = Singleton() | |
} | |
return Static.instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
int main(int argc, const char * argv[]) | |
{ | |
std::thread t([]{ | |
std::cout << "Hello, Lambda!" << std::endl; | |
}); | |
t.join(); |