This file contains hidden or 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
| let image = #imageLiteral(resourceName: "Arrow.gif") | |
| let imageRep = image.representations.first! as! NSBitmapImageRep | |
| let numFrames = imageRep.value(forProperty: NSImageFrameCount) as! Int | |
| let numLoops = imageRep.value(forProperty: NSImageCurrentFrameDuration) as! Float | |
| var cgImages = [CGImage]() | |
| var nsImages = [NSImage]() | |
| var size = NSSize() | |
| for frame in 0..<numFrames { |
This file contains hidden or 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
| // 1. Don't compare to `nil`, only to force unwrap later. Just use conditional binding: | |
| func allOfferCards() -> [OfferCard]{ | |
| guard let dataSource = dataSource else { return [] } | |
| let numberOfCards = self.dataSource.kolodaNumberOfCards(self) | |
| var offerCards = [OfferCard]() | |
| for i in 0..<numberOfCards { |
This file contains hidden or 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
| extension String { | |
| func mostFrequentWord() -> String? { | |
| return Dictionary( | |
| grouping: self | |
| .trimmingCharacters(in: CharacterSet.letters) | |
| .lowercased() | |
| .components(separatedBy: CharacterSet.whitespacesAndNewlines), | |
| by: { $0 } | |
| ) | |
| .max(by:) { $0.value.count < $1.value.count }?.key // `key` is word, `value` is array of word, repeated `count` times |
This file contains hidden or 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 Cocoa | |
| let path = "/Users/You/Pick/Any/Random/File/On/Your/System.txt" | |
| let destination = URL(fileURLWithPath: path) | |
| let progress: Progress = { | |
| let p = Progress(parent: nil, userInfo: [ | |
| .fileOperationKindKey: Progress.FileOperationKind.downloading, | |
| .fileURLKey: destination, | |
| ]) |
This file contains hidden or 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 Cocoa | |
| let path = "/Users/You/Pick/Any/Random/File/On/Your/System.txt" | |
| let destination = URL(fileURLWithPath: path) | |
| let progress: Progress = { | |
| let p = Progress(parent: nil, userInfo: [ | |
| .fileOperationKindKey: Progress.FileOperationKind.downloading, | |
| .fileURLKey: destination, | |
| ]) |
This file contains hidden or 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 UIKit | |
| import PlaygroundSupport | |
| class ArcView: UIView { | |
| private var strokeWidth: CGFloat { | |
| return CGFloat(min(self.bounds.width, self.bounds.height) * 0.25) | |
| } | |
| override open func draw(_ rect: CGRect) { | |
| super.draw(rect) |
This file contains hidden or 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
| #!/usr/bin/ruby | |
| def disrespect_privacy(symbol, &block) # access private methods in a block | |
| raise ArgumentError, 'Block must be specified' unless block_given? | |
| block_binding = block.binding | |
| target_object = block_binding.local_variable_get(symbol) | |
| block_binding.local_variable_set(symbol, PrivacyViolator.new(target_object)) | |
| yield |
This file contains hidden or 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 Dispatch | |
| import Foundation | |
| // The Weak struct is the weak wrapper | |
| struct Weak<T: AnyObject> { | |
| weak var object: T? | |
| } | |
| // Stand-in for AUGraphAddRenderNotify | |
| func call( |
This file contains hidden or 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 Foundation | |
| struct S<T> { | |
| let elements: [T] | |
| } | |
| extension S: Decodable where T: Decodable { | |
| init(from decoder: Decoder) throws { | |
| let container = try decoder.unkeyedContainer() | |
| let s = sequence(state: container, next: { |
This file contains hidden or 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
| def letterPattern(size): | |
| # TODO: your code goes here | |
| result = "" | |
| for i in range(size): | |
| p = 65 | |
| for j in range(i, size): | |
| result += chr(p) | |
| p += 1 | |
OlderNewer