Skip to content

Instantly share code, notes, and snippets.

View superhard's full-sized avatar
🎯
Focusing

Artem superhard

🎯
Focusing
View GitHub Profile
@brennanMKE
brennanMKE / Async.swift
Last active March 6, 2023 13:01
Blocking with Semaphores and DispatchGroups in Swift
import PlaygroundSupport
import Foundation
class Worker {
private let queue = DispatchQueue.global(qos: .background)
private let serialQueue = DispatchQueue(label: "com.acme.serial")
public private(set) var count = 0
func incrementCount() {
@lattner
lattner / TaskConcurrencyManifesto.md
Last active May 11, 2025 07:07
Swift Concurrency Manifesto
@ylem
ylem / CenterItemInCollectionView.playground
Last active October 22, 2024 04:04
Scrolling item on a horizontal UICollectionView, stopped item on center of screen.
//: Playground - noun: a place where people can play
import UIKit
import PlaygroundSupport
class WLCollectionCell: UICollectionViewCell {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@karnlund
karnlund / UIViewFromNib.swift
Last active June 1, 2018 16:20
This is fromNib methods converted for Swift 3. This is obtained from StackOverflow here http://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift
// This came from StackOverflow
// http://stackoverflow.com/questions/24857986/load-a-uiview-from-nib-in-swift
//
// https://gist.github.com/karnlund/b666acc88532d5f1ca591dd3580605cc
import UIKit
public extension UIView {
public class func fromNib(_ nibName: String? = nil) -> Self? {
return loadFromNib(nibName)
@kunikullaya
kunikullaya / Date+Extension.swift
Created January 18, 2017 05:21
Date Extension for Swift
import Foundation
extension Date {
func toString(format: String = "yyyy-MM-dd") -> String {
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.dateFormat = format
return formatter.string(from: self)
}
@sauvikatinnofied
sauvikatinnofied / MediumBlogFontHandling_FullCode.swift
Last active October 25, 2023 14:57
MediumBlogFontHandling_FullCode
import Foundation
import UIKit
// Usage Examples
let system12 = Font(.system, size: .standard(.h5)).instance
let robotoThin20 = Font(.installed(.RobotoThin), size: .standard(.h1)).instance
let robotoBlack14 = Font(.installed(.RobotoBlack), size: .standard(.h4)).instance
let helveticaLight13 = Font(.custom("Helvetica-Light"), size: .custom(13.0)).instance
struct Font {
import Foundation
import UIKit
// Usage Examples
let shadowColor = Color.shadow.value
let shadowColorWithAlpha = Color.shadow.withAlpha(0.5)
let customColorWithAlpha = Color.custom(hexString: "#123edd", alpha: 0.25).value
enum Color {
import UIKit
extension UITableView {
func registerNib<T: UITableViewCell>(forCellType type: T.Type) {
let name = String(describing: type)
let nib = UINib(nibName: name, bundle: nil)
register(nib, forCellReuseIdentifier: name)
}
func registerNib<T: UIView>(forHeaderFooterType type: T.Type) {

FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.


Effective Engineer - Notes

What's an Effective Engineer?

import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
/// define an operation success or error result
enum Result<T> {
case error(Error)
case success(T)
}