Skip to content

Instantly share code, notes, and snippets.

import Foundation
struct ProbingDictionary<Key: Hashable, Value> {
enum Item: CustomStringConvertible {
case element(Key, Value)
case empty
case tombstone
var isEmpty: Bool {
if case .empty = self {
@khanlou
khanlou / ObjectStorage.swift
Created April 1, 2019 21:02
ObjectStorage 3.0
//
// ObjectStorage.swift
// Soroush Khanlou
//
// Created by Soroush Khanlou on 3/8/19.
// Copyright © 2019 Soroush Khanlou. All rights reserved.
//
import Foundation
@khanlou
khanlou / URLRequest.swift
Last active February 9, 2019 20:33 — forked from peterprokop/URLRequest.swift
Print NSURLRequest in cURL format
//
// URLRequest.swift
//
// Created by Peter Prokop on 17/08/2017.
// Modified by Soroush Khanlou on 09/12/2018.
import Foundation
public extension URLRequest {
struct LazyUniquedSequence<Element>: Sequence {
let base: AnySequence<Element>
let isEqual: (Element, Element) -> Bool
init<S: Sequence>(_ sequence: S, isEqual: @escaping (Element, Element) -> Bool) where S.Element == Element {
self.base = AnySequence(sequence)
self.isEqual = isEqual
}
@khanlou
khanlou / SKSerialInputStream.h
Last active November 10, 2022 11:41
Partially adapted from AFMultipartBodyStream
//
// SKSerialInputStream.h
// inputstream
//
// Created by Soroush Khanlou on 11/4/18.
// Copyright © 2018 Soroush Khanlou. All rights reserved.
//
#import <Foundation/Foundation.h>
struct LazyUniquedSequence<Element>: Sequence {
let base: AnySequence<Element>
let isEqual: (Element, Element) -> Bool
init<S: Sequence>(_ sequence: S, isEqual: @escaping (Element, Element) -> Bool) where S.Element == Element {
self.base = AnySequence(sequence)
self.isEqual = isEqual
}
@interface HTTPMethod: NSString
+ (HTTPMethod *)GET;
+ (HTTPMethod *)POST;
@end
@khanlou
khanlou / ImageFetcher.kt
Created July 8, 2018 15:06
Simple image fetching and caching example. Intended for Firebase but the fetching architecture could be abstracted out. Dependent on `com.jakewharton.disklrucache.DiskLruCache`.
package amal.global.amal
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.LruCache
import com.google.firebase.storage.StorageReference
import com.jakewharton.disklrucache.DiskLruCache
import java.io.File
import java.security.MessageDigest
import UIKit
class PassThroughView: UIView {
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let result = super.hitTest(point, with: event)
if result == self { return nil }
return result
}
public struct ReversibleRange<Bound>: Equatable where Bound: Comparable {
public let startingBound: Bound
public let endingBound: Bound
public init(startingBound: Bound, endingBound: Bound) {
self.startingBound = startingBound
self.endingBound = endingBound
}
public var isReversed: Bool {