Skip to content

Instantly share code, notes, and snippets.

View amomchilov's full-sized avatar

Alexander Momchilov amomchilov

View GitHub Profile
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)
@amomchilov
amomchilov / DownloadProgressIndicatorDemo.swift
Last active November 3, 2023 08:44 — forked from mminer/DownloadProgressIndicatorDemo.swift
Displays a progress indicator on a file in the Finder.
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,
])
@amomchilov
amomchilov / Download Progress Example.swift
Last active June 5, 2019 16:00
An example of using (NS)Progress to show a progress bar in Finder
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,
])
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
// 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 {
@amomchilov
amomchilov / Gif stitcher
Last active June 28, 2023 19:52
Vertically stitches frames of a GIF into a single image
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 {