Skip to content

Instantly share code, notes, and snippets.

View janeshsutharios's full-sized avatar

Janesh suthar janeshsutharios

View GitHub Profile
// WastingTimeOnStackOverflowTests.swift Created by mason on 2016-09-18.
import XCTest
/// Measures performance of two different ways of checking whether an index is valid
/// for a given array (the variable "a" is an array of 1,000,000 unique strings, and
/// "val" is the index to be checked):
///
/// a.indices.contains(val)
/// vs:
@janeshsutharios
janeshsutharios / EncryptionHelper.swift
Created December 3, 2021 05:17
Encryption in iOS
//
// EncryptionHelper.swift
// Demo3
//
//
import Foundation
import CommonCrypto
struct AES {
@janeshsutharios
janeshsutharios / PaddingUILabel.swift
Created April 10, 2021 05:59
PaddingUILabel.swift
class PaddingLabel: UILabel {
@IBInspectable var topInset: CGFloat = 5.0
@IBInspectable var bottomInset: CGFloat = 5.0
@IBInspectable var leftInset: CGFloat = 7.0
@IBInspectable var rightInset: CGFloat = 7.0
override func drawText(in rect: CGRect) {
let insets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
super.drawText(in: rect.inset(by: insets))
@janeshsutharios
janeshsutharios / PaddingUItextField.swift
Created April 10, 2021 05:59
PaddingUItextField.swift
class PaddingTextField: UITextField {
let padding = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8)
override open func textRect(forBounds bounds: CGRect) -> CGRect {
return bounds.inset(by: padding)
}
override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return bounds.inset(by: padding)
let imageCache = NSCache<NSString, UIImage>()
extension UIImageView {
func loadImageUsingCache(withUrl urlString : String) {
let url = URL(string: urlString)
if url == nil {return}
self.image = nil
if let cachedImage = imageCache.object(forKey: urlString as NSString) {
self.image = cachedImage
return
}
@janeshsutharios
janeshsutharios / ClouserDataBinding.swift
Last active July 15, 2019 07:01
Data Binding through Clousers
//Step 1:
//Create button clouser
var tapsOnButtonClouser:() -> () = {}
var isTempBool = false
//Step 2: Setup that function
func setUpClouser() {
tapsOnButtonClouser = { [weak self] in
guard let localSelf = self else {return}
localSelf.isTempBool = !localSelf.isTempBool
print("Temp Bool changed to--> ",localSelf.isTempBool)
@janeshsutharios
janeshsutharios / InternetTime
Created March 27, 2019 10:40
Get time from internet
import UIKit
extension Formatter {
static let enUSPOSIX: DateFormatter = {
let formatter = DateFormatter()
@janeshsutharios
janeshsutharios / Obfuscator.swift
Created February 21, 2019 11:59 — forked from DejanEnspyra/Obfuscator.swift
Obfuscation of hard-coded security-sensitive strings.
//
// Obfuscator.swift
//
// Created by Dejan Atanasov on 2017-05-31.
//
import Foundation
class Obfuscator: AnyObject {
@janeshsutharios
janeshsutharios / Webservice.swift
Last active November 6, 2020 08:01
Webservice call
// MARK: - WelcomeElement
struct WelcomeElement: Codable {
let userID, id: Int
let title: String
let completed: Bool
enum CodingKeys: String, CodingKey {
case userID = "userId"
case id, title, completed
}
@janeshsutharios
janeshsutharios / JsonPlist.plist
Created March 12, 2018 04:57
Sample Plist File
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DeviceDictionary</key>
<dict>
<key>phone</key>
<string>iPhone 6s</string>
</dict>
<key>ToolString</key>