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
#!/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 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 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 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 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 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 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 { |
NewerOlder