Skip to content

Instantly share code, notes, and snippets.

View yasirmturk's full-sized avatar
💻
the smart engineer

Yasir Türk yasirmturk

💻
the smart engineer
View GitHub Profile
@yasirmturk
yasirmturk / ExecuteOnceAtATime.m
Created July 8, 2014 07:54
Avoid multiple Executions of a method at any given time
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
dispatch_queue_t renderQueue = dispatch_queue_create("com.throttling.queue", NULL);
- (void) onlyExecuteOnceAtATime {
if (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) == 0) {
dispatch_async(renderQueue, ^{
// execution code goes here
dispatch_semaphore_signal(semaphore);
});
}
@yasirmturk
yasirmturk / YTMXResolver.h
Created August 12, 2014 05:49
Quick MX resolver class can be modified to resolve other DNS records like NS, PTR, TXT
//
// YTMXResolver.h
//
// Copyright 2011 Yasir M Turk. All rights reserved.
//
#import <Foundation/Foundation.h>
#include <dns_sd.h>
@yasirmturk
yasirmturk / UIStackView+RemoveAll.swift
Created April 15, 2020 07:49
Remove all arranged subviews from UIStackView properly
import UIKit
extension UIStackView {
@discardableResult
func removeAllArrangedSubviews() -> [UIView] {
return arrangedSubviews.reduce([UIView]()) { $0 + [removeArrangedSubViewProperly($1)] }
}
func removeArrangedSubViewProperly(_ view: UIView) -> UIView {
removeArrangedSubview(view)
@yasirmturk
yasirmturk / ModelMockable.swift
Last active December 14, 2021 19:50
Protocol to create models from json
import Foundation
final class MockableTests {
struct MockNotFound: Error {
let message: String
}
}
extension Bundle {
static let tests = Bundle(for: MockableTests.self)
@yasirmturk
yasirmturk / SnapshotContainer.swift
Last active January 14, 2022 16:08
iOS/Swift Snapshot Test utility for UIView, UITableCell, UICollectionViewCell and SwiftUI
import UIKit
final class SnapshotContainer: UIView {
let view: UIView
init(_ view: UIView, width: CGFloat, backgroundColor: UIColor = .white) {
self.view = view
super.init(frame: .zero)
@yasirmturk
yasirmturk / MaxSizeCollection.swift
Created February 17, 2023 23:37
max size collection in swift like java and kotlin
@propertyWrapper
public struct MaxSizeCollection<Value: Collection> {
private let _maxSize: UInt?
public var _value: Value
public init(wrappedValue value: Value) {
_value = value
_maxSize = nil
}