Instantly share code, notes, and snippets.

View URLRequest.swift
//
// URLRequest.swift
//
// Created by Peter Prokop on 17/08/2017.
// Modified by Soroush Khanlou on 09/12/2018.
import Foundation
public extension URLRequest {
View LazyUniquedSequence.swift
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
}
View SKSerialInputStream.h
//
// SKSerialInputStream.h
// inputstream
//
// Created by Soroush Khanlou on 11/4/18.
// Copyright © 2018 Soroush Khanlou. All rights reserved.
//
#import <Foundation/Foundation.h>
View LazyUniquedCollection.swift
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
}
View HTTPMethod.h
@interface HTTPMethod: NSString
+ (HTTPMethod *)GET;
+ (HTTPMethod *)POST;
@end
View ImageFetcher.kt
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
View PassThroughView.swift
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
}
View ReversibleRange.swift
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 {
View BinaryFloating+Scaling.swift
public extension BinaryFloatingPoint {
public func scaled(from source: ReversibleRange<Self>, to destination: ReversibleRange<Self>) -> Self {
let destinationStart = destination.lowerBound
let destinationEnd = destination.upperBound
let selfMinusLower = self - source.lowerBound
let sourceUpperMinusLower = source.upperBound - source.lowerBound
let destinationUpperMinusLower = destinationEnd - destinationStart
View CharacterSet+Swift.swift
extension CharacterSet {
func contains(_ character: Character) -> Bool {
guard let firstScalar = character.unicodeScalars.first else { return false }
return self.contains(firstScalar)
}
}