Skip to content

Instantly share code, notes, and snippets.

View sunilsharma08's full-sized avatar
🏠
Working from home

Sunil Sharma sunilsharma08

🏠
Working from home
View GitHub Profile
/** Throttle wraps a block with throttling logic, guarantueeing that the block will never be called (by enquueing
asynchronously on `queue`) more than once each `interval` seconds. If the wrapper callback is called more than once
in an interval, it will use the most recent call's parameters when eventually calling the wrapped block (after `interval`
has elapsed since the last call to the wrapped function) - i.e. calls are not queued and may get 'lost' by being superseded
by a newer call. */
public func throttle<P>(interval: TimeInterval, queue: DispatchQueue, _ block: ((P) -> ())) -> ((P) -> ()) {
var lastExecutionTime: TimeInterval? = nil
var scheduledExecutionParameters: P? = nil
let mutex = Mutex()
@sunilsharma08
sunilsharma08 / AssociationHelpers.swift
Created January 20, 2021 10:03 — forked from aufflick/AssociationHelpers.swift
Helpers to assist using the ObjC runtime to associate both objects and structs in Swift
// Associated wrapper by WeZZard : https://wezzard.com/2015/10/09/associated-object-and-swift-struct/
// Type safe helpers inspired by Tikitu de Jager : https://medium.com/@ttikitu/swift-extensions-can-add-stored-properties-92db66bce6cd#.mx6ekrw16
public final class AssociatedStruct<T>: NSObject, NSCopying {
public typealias Type = T
public let value: Type
public init(_ value: Type) { self.value = value }
@sunilsharma08
sunilsharma08 / Apple_mobile_device_types.txt
Created September 17, 2020 05:00 — forked from adamawolf/Apple_mobile_device_types.txt
List of Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names
i386 : iPhone Simulator
x86_64 : iPhone Simulator
iPhone1,1 : iPhone
iPhone1,2 : iPhone 3G
iPhone2,1 : iPhone 3GS
iPhone3,1 : iPhone 4
iPhone3,2 : iPhone 4 GSM Rev A
iPhone3,3 : iPhone 4 CDMA
iPhone4,1 : iPhone 4S
iPhone5,1 : iPhone 5 (GSM)
@sunilsharma08
sunilsharma08 / MemoryAddress.swift
Created September 12, 2020 02:47 — forked from nyg/MemoryAddress.swift
Get the memory address of both class and structure instances in Swift.
// https://stackoverflow.com/a/45777692/5536516
import Foundation
struct MemoryAddress<T>: CustomStringConvertible {
let intValue: Int
var description: String {
let length = 2 + 2 * MemoryLayout<UnsafeRawPointer>.size
@sunilsharma08
sunilsharma08 / README-Template.md
Created May 2, 2020 20:02 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
@sunilsharma08
sunilsharma08 / gist:2c1216e340f8d44bb858d52053283bf9
Created July 8, 2019 13:12 — forked from floriankugler/gist:6870499
Mapping of NSURLConnection to NSURLSession delegate methods. Created by Mattt Thompson.
NSURLConnection | NSURLSession
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connectionShouldUseCredentialStorage: |
------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------
NSURLConnectionDelegate connection:willSendRequestForAuthenticationChallenge: | NSURLSessionDelegate URLSession:didReceiveChallenge:completionHandler:
| N
// MyURLStreamTask.swift
// Demonstrates using an NSURLSessionStreamTask to implement a bidirectional TCP socket connection
//
// by [email protected] 2017-03-07
// distribution: BSD 2-clause
//
import Foundation
class MyURLStreamTask {
@sunilsharma08
sunilsharma08 / UIView+round.swift
Created February 14, 2019 04:50 — forked from Sorix/UIView+round.swift
Round specified corners of UIView
// Example: view.round([.TopLeft, .TopRight], radius: 15)
extension UIView {
/**
Rounds the given set of corners to the specified radius
- parameter corners: Corners to round
- parameter radius: Radius to round to
*/
func round(corners: UIRectCorner, radius: CGFloat) {
@sunilsharma08
sunilsharma08 / UIImage+PixelColor.swift
Created May 22, 2018 06:00 — forked from marchinram/UIImage+PixelColor.swift
iOS Swift UIImage subscript extension to get pixel color
import UIKit
extension UIImage {
subscript (x: Int, y: Int) -> UIColor? {
if x < 0 || x > Int(size.width) || y < 0 || y > Int(size.height) {
return nil
}