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 / 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 / time_ago_since_now.dart
Created March 1, 2019 06:08
Flutter Time ago calculator
static String timeAgoSinceDate(String dateString, {bool numericDates = true}) {
DateTime date = DateTime.parse(dateString);
final date2 = DateTime.now();
final difference = date2.difference(date);
if ((difference.inDays / 365).floor() >= 2) {
return '${(difference.inDays / 365).floor()} years ago';
} else if ((difference.inDays / 365).floor() >= 1) {
return (numericDates) ? '1 year ago' : 'Last year';
} else if ((difference.inDays / 30).floor() >= 2) {
@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]