Skip to content

Instantly share code, notes, and snippets.

@greenchiu
greenchiu / Promise.swift
Last active March 26, 2020 13:49
Practice Promise
import Foundation
enum PromiseError: Error {
case invaild
}
public struct AsyncExecutor {
public static let main = AsyncExecutor()
public static let background = AsyncExecutor(qos: .default)
private let queue: DispatchQueue
protocol X {
func hello()
}
extension X {
func hello() {
print("Hello")
}
}
class UnivalCountSolution {
private var count = 0
private var testCount = 0
func soultion(_ root: TreeNode?) -> Int {
guard let root = root else {
return 0
}
isUnivalSubtree(root)
return count
}
@greenchiu
greenchiu / Finding_smallest_common_element_in_two_arrays.swift
Last active December 4, 2019 07:47
Finding smallest common element in two arrays
func Solution(_ nums1:[Int], _ nums2: [Int]) -> Int? {
let set: Set<Int> = Set(nums1)
var result: Int?
for element in nums2 {
if set.contains(element) {
if let currentMin = result {
result = min(element, currentMin)
continue
}
result = element
@greenchiu
greenchiu / SongCell.m
Last active October 15, 2017 16:00
Original code.
- (viod)loadSongInfo:(LocalSongInfo *)inSongInfo
{
// load image
if (inSongInfo.source == ... ) {
self.coverImage.image = [[MediaItem itemWithSongID:...].artwork imageWith...];
}
else if (inSongInfo.source == ... ) {
SongMetadata *metadata = ...
[metadata getImagWithCallback:...]
}