Skip to content

Instantly share code, notes, and snippets.

@lattner
lattner / TaskConcurrencyManifesto.md
Last active June 19, 2024 13:41
Swift Concurrency Manifesto
extension Signal where Error == NoError {
public func sample(each timeInterval: DispatchTimeInterval,
on scheduler: DateScheduler = QueueScheduler()) -> Signal<[Value], NoError> {
return Signal<[Value], NoError> { observer in
let valueHolder : MutableProperty<[Value]> = MutableProperty<Value>([])
let disposable = CompositeDisposable()
var sampler: Signal<(), NoError>? = nil
disposable += timer(interval: until, on: QueueScheduler()).startWithSignal { signal, _ in
signal = innerSignal.map { _ in () }
}
import Cocoa
import MASShortcut
func pow() {
let rect = NSScreen.mainScreen()?.frame
let window = NSWindow(contentRect: rect!, styleMask: NSBorderlessWindowMask, backing: .Buffered, `defer`: false)
window.backgroundColor = NSColor.clearColor()
window.opaque = false
window.alphaValue = 1
window.makeKeyAndOrderFront(NSApplication.sharedApplication())
@chriseidhof
chriseidhof / tableviews.swift
Last active October 15, 2023 20:56
trySwift
import UIKit
// If you enjoyed this talk (video link will be up soon), then you might also enjoy our book Advanced Swift: http://www.objc.io/books/advanced-swift
struct Person {
let name: String
let city: String
}
let people = [
@gwengrid
gwengrid / TypeErasure.swift
Last active September 12, 2018 05:14
Example of type erasure with Pokemon
class Thunder { }
class Fire { }
protocol Pokemon {
typealias PokemonType
func attack(move:PokemonType)
}
struct Pikachu: Pokemon {
typealias PokemonType = Thunder
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active June 5, 2024 22:16
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@TonnyXu
TonnyXu / iOSUnitTestBundlePath.m
Created January 29, 2012 08:49
Use bundleForClass to get the unit test bundle's path
/*
This tips is extremely useful when you test your CoreData app in Unit Test.
*/
// iOS app is an executable bundle, means the `main` method is
// included inside app bundle, so `mainBundle` returns the app bundle
//
// See doc at https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003624
NSBundle *appBundle = [NSBundle mainBundle];