Skip to content

Instantly share code, notes, and snippets.

@khoi
khoi / curry.swift
Last active November 9, 2017 15:58
emoji oriented programming
//Emojify https://github.com/thoughtbot/Curry/blob/master/Source/Curry.swift
import Foundation
public func 🍛<🐶, 😺>(_ function: @escaping (🐶) -> 😺) -> (🐶) -> 😺 {
return { (a: 🐶) -> 😺 in function(a) }
}
public func 🍛<🐶, 😺, 🐭>(_ function: @escaping (🐶, 😺) -> 🐭) -> (🐶) -> (😺) -> 🐭 {
return { (a: 🐶) -> (😺) -> 🐭 in { (b: 😺) -> 🐭 in function(a, b) } }
}
@khoi
khoi / readerwriters.swift
Created August 16, 2021 06:21
Reader Writers Lock Property Wrapper in Swift
class A {
@ReadersWriter var a = 1
}
public final class ReadersWriterLock {
private var lock: UnsafeMutablePointer<pthread_rwlock_t>
public init() {
self.lock = UnsafeMutablePointer.allocate(capacity: 1)
let status = pthread_rwlock_init(lock, nil)
Trăm năm trong cõi người ta,
Chữ tài chữ mệnh khéo là ghét nhau.
Trải qua một cuộc bể dâu,
Những điều trông thấy mà đau đớn lòng.
Lạ gì bỉ sắc tư phong,
Trời xanh quen thói má hồng đánh ghen.
Cảo thơm lần giở trước đèn,
Phong tình có lục còn truyền sử xanh.
Rằng năm Gia Tĩnh triều Minh,
Bốn phương phẳng lặng, hai kinh vững vàng.