Skip to content

Instantly share code, notes, and snippets.

View DineshKachhot's full-sized avatar
🎯
Focusing

Dinesh Kachhot DineshKachhot

🎯
Focusing
View GitHub Profile
@DineshKachhot
DineshKachhot / ReactClearCache&StartNPM
Created August 18, 2020 05:20
React: Clear Cache and Start NPM
npm start -- --reset-cache
fileprivate func encryptionAES(data: Data, key: Data, IV: Data) -> String? {
var numberOfBytesEncrypted : size_t = 0
let size = data.count + kCCKeySizeAES128
var encrypted = Data(count: size)
let cryptStatus = IV.withUnsafeBytes { ivBytes in
encrypted.withUnsafeMutableBytes { encryptedBytes in
data.withUnsafeBytes { dataBytes in
key.withUnsafeBytes { keyBytes in
CCCrypt(CCOperation(kCCEncrypt), CCAlgorithm(kCCAlgorithmAES), CCOptions(kCCOptionPKCS7Padding), keyBytes, key.count, ivBytes, dataBytes, data.count, encryptedBytes, size, &numberOfBytesEncrypted)
}
@DineshKachhot
DineshKachhot / BluetoothMacAddress.swift
Created April 22, 2020 05:55
Get Bluetooth Mac address of self device and discovered devices
Self Bluetooth mac address by
UIDevice.current.identifierForVendor?.uuidString
Inside didDiscover delegate you will have a peripheral with id
peripheral.identifier.uuidString
//
// FormViewSocial.swift
// SwiftUI_Practice
//
// Created by Dinesh Kachhot on 05/03/20.
// Copyright © 2020 KD. All rights reserved.
//
import SwiftUI
@DineshKachhot
DineshKachhot / iterm2.md
Created January 1, 2020 10:19 — forked from squarism/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)
@DineshKachhot
DineshKachhot / ImageResponse.swift
Created September 7, 2019 02:09
NSURLSession GET Request - Swift 4.2
struct ImageResponse: Codable {
var message:String
var totalRecord:Int
var totalPage:Int
var nextPage:String
var images:[Image]
enum CodingKeys: String, CodingKey {
case message
case totalRecord
@DineshKachhot
DineshKachhot / NSURLSession POST request
Created September 7, 2019 02:06
NSURLSession POST request - Swift 4.2
guard let urlEncodedString = (AppConstants.URL.sendDeviceTokekn).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
return
}
let url = URL(string: urlEncodedString)!
let urlRequest = NSMutableURLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 60.0)
urlRequest.setValue("Application/json", forHTTPHeaderField: "Content-Type")
urlRequest.setValue("Application/json", forHTTPHeaderField: "Accept")
urlRequest.httpMethod = "POST"
let params: [String : Any] = ["txDeviceToken":token, "tDeviceOs":2]
@DineshKachhot
DineshKachhot / NSTimeInterval+AudioDurationFormat.swift
Created August 29, 2019 06:49
Audio/Video Duration formate in Swift 4.2
import Foundation
extension TimeInterval {
struct DateComponents {
static let formatterPositional: DateComponentsFormatter = {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour,.minute,.second]
formatter.unitsStyle = .positional
formatter.zeroFormattingBehavior = .pad
return formatter
@DineshKachhot
DineshKachhot / ForceUpdateAppVersion.swift
Last active October 29, 2023 06:33
Force Update iOS App while API has major update
import Foundation
enum VersionError: Error {
case invalidResponse, invalidBundleInfo
}
class ForceUpdateAppVersion {
class func isForceUpdateRequire(apiVersion:Int) -> Bool {
func update() {
@DineshKachhot
DineshKachhot / MemoryAddress.swift
Created May 28, 2019 12:54
Check memory address of Value type and Reference type in Swift 5
// Get memory address of value type
func address(of value: UnsafeRawPointer) -> Int {
return unsafeBitCast(value, to: Int.self)
}
var num1 = 55
var num2 = 55
print(NSString(format: "%p", address(of:&num1))) // -> "0x11fc3c5a0"
print(NSString(format: "%p", address(of:&num2))) // -> "0x11fc3c5a8"
num2 = 77