Skip to content

Instantly share code, notes, and snippets.

View alemar11's full-sized avatar

Alessandro alemar11

View GitHub Profile
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@alemar11
alemar11 / Scheduling-AppDelegate.swift
Created February 20, 2018 18:44 — forked from shaps80/Scheduling-AppDelegate.swift
NSNotification Scheduling Service in Swift. (the only required file is `SchedulingService.swift`)
//
// AppDelegate.swift
// Scheduling
//
// Created by Shaps Benkau on 19/02/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
//
import UIKit
@alemar11
alemar11 / MessageQueue.swift
Created February 21, 2018 14:59 — forked from yume190/MessageQueue.swift
仿 Android HandlerThread 的 Message Queue(一小部分功能)
import Foundation
public class MessageQueue {
public typealias Message = Void -> Void
private var exitFlag = false
private var messageQueue:[Message] = []
private var loopInterval:Double
@alemar11
alemar11 / Channel.swift
Created March 9, 2018 08:22 — forked from gokselkoksal/Channel.swift
Channel implementation
public class Channel<Value> {
private class Subscription {
weak var object: AnyObject?
private let notifyBlock: (Value) -> Void
private let queue: DispatchQueue
var isValid: Bool {
return object != nil
@alemar11
alemar11 / HTTPStatusCode.swift
Created April 4, 2018 13:57
HTTP Status Codes
enum HTTPStatusCode: Int {
// MARK: - 100 Informational
case Continue = 100
case SwitchingProtocols
case Processing
// MARK: - 200 Success
case Ok = 200
case Created
case Accepted
case NonAuthoritativeInformation
@alemar11
alemar11 / UIAccessorizedTextField.swift
Created April 6, 2018 10:55 — forked from damienlaughton/UIAccessorizedTextField.swift
UIAccessorizedTextField is an iOS friendly alternative to the drop down list
//
// UIAccessorizedTextField.swift
// AccessorizedTextField
//
// Created by Damien Laughton on 28/03/2018.
// 2018 Mobilology Limited. No rights reserved.
//
import Foundation
import UIKit
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
fileprivate let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
fileprivate var array = [Element]()
}
// MARK: - Properties
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
fileprivate let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
fileprivate var array = [Element]()
}
// MARK: - Properties
import CoreData
/// Manages Core Data Persistent History.
///
/// When using Core Data in multiple targets, e.g. an app as well as a file provider, it is crucial to merge changes from one
/// target into another because otherwise you would end up with inconsistent state. To that end, this Apple introduced
/// persistent history, which is a linear stream of changes that can be merged into the current context. This service takes
/// advantage of this feature by providing a simple interface for merging and deleting history. The latter is needed to free up
/// space after the history has been consumed by all targets. It uses history transactions' timestamps in order to determine
/// what to delete.
@alemar11
alemar11 / WorkUnitExecutor.swift
Created June 15, 2018 10:21 — forked from deze333/WorkUnitExecutor.swift
Multi-thread to single-thread synchronized executor pattern in Swift (playground)
// Multi to single thread execution
// Credits go to https://www.reddit.com/r/swift/comments/7ijbt0/whats_a_good_way_to_make_sync_calls_from_swift_to/dr4iwxr/
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(3000)) {
print("Done")
PlaygroundPage.current.finishExecution()