Skip to content

Instantly share code, notes, and snippets.

View damodarnamala's full-sized avatar

Damodar damodarnamala

  • Hyderabad
View GitHub Profile
@damodarnamala
damodarnamala / String+AES.swift
Created September 16, 2022 04:34 — forked from yutelin/String+AES.swift
String+AES.swift
import Foundation
import CryptoSwift
extension String {
func aesEncrypt(key: String, iv: String) throws -> String{
let data = self.dataUsingEncoding(NSUTF8StringEncoding)
let enc = try AES(key: key, iv: iv, blockMode:.CBC).encrypt(data!.arrayOfBytes(), padding: PKCS7())
let encData = NSData(bytes: enc, length: Int(enc.count))
let base64String: String = encData.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0));
@damodarnamala
damodarnamala / FileUploader.swift
Created September 16, 2022 04:33 — forked from ncerezo/FileUploader.swift
Alamofire multipart upload
//
// FileUploader.swift
//
// Copyright (c) 2015 Narciso Cerezo Jiménez. All rights reserved.
// Largely based on this stackoverflow question: http://stackoverflow.com/questions/26121827/uploading-file-with-parameters-using-alamofire/28467829//
import Foundation
import Alamofire
private struct FileUploadInfo {
@propertyWrapper
public struct AnyProxy<EnclosingSelf, Value> {
private let keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>
public init(_ keyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>) {
self.keyPath = keyPath
}
@available(*, unavailable, message: "The wrapped value must be accessed from the enclosing instance property.")
public var wrappedValue: Value {
import SwiftUI
import Combine
public struct ChangeObserver<V: Equatable>: ViewModifier {
public init(newValue: V, action: @escaping (V) -> Void) {
self.newValue = newValue
self.newAction = action
}
private typealias Action = (V) -> Void
@damodarnamala
damodarnamala / DateFormatter+Docs.swift
Created September 16, 2022 04:28 — forked from shaps80/DateFormatter+Docs.swift
DateFormatter with better header docs
import Foundation
public extension DateFormatter {
/**
Makes a new DateFormatter with the specified format, calendar and locale.
Characters Example Description
---------------------------------------------------------------------------------------------------------------
Year
@damodarnamala
damodarnamala / CardDecorating.swift
Created September 16, 2022 04:27 — forked from shaps80/CardDecorating.swift
A simple protocol for creating a 'Card' style component in Swift.
import UIKit
/// Decorates a view as a `Card`. Requires that the view is embedded in some `contentView`
public protocol CardDecorating {
/// View that will be styled as a card. Should hold the `contentView`.
var cardView: UIView { get }
/// Holds the main content. Subviews should be added to this view.
var contentView: UIView { get }
}
extension Encodable {
var debugJson: String {
(try? JSONEncoder().encode(self).debugJson) ?? ""
}
}
extension Data {
var debugJson: String {
String(decoding: self, as: UTF8.self)
}
@damodarnamala
damodarnamala / Flipped.swift
Created September 16, 2022 04:25 — forked from shaps80/Flipped.swift
Provides a CGAffineTransform suitable for flipping the Y Axis.
private func flipped(size: CGSize) -> CGAffineTransform {
let mirror = CGAffineTransform(scaleX: 1, y: -1)
let translate = CGAffineTransform(translationX: 0, y: size.height)
return mirror.concatenating(translate)
}
@damodarnamala
damodarnamala / Store.swift
Created September 16, 2022 04:24 — forked from shaps80/Store.swift
Atomic RangeReplaceableCollection Storage in Swift
import Foundation
public final class Store<Element>: RangeReplaceableCollection {
public typealias Index = Int
public typealias SubSequence = Store<Element>
public var startIndex: Index { queue.sync { storage.startIndex } }
public var endIndex: Index { queue.sync { storage.endIndex } }
public func index(after i: Index) -> Index { queue.sync { storage.index(after: i) } }
@damodarnamala
damodarnamala / AVPlayer+Scrubbing.swift
Created September 16, 2022 04:24 — forked from shaps80/AVPlayer+Scrubbing.swift
Enables smooth frame-by-frame scrubbing (in both directions) – similar to Apple's applications.
public enum Direction {
case forward
case backward
}
internal var player: AVPlayer?
private var isSeekInProgress = false
private var chaseTime = kCMTimeZero
private var preferredFrameRate: Float = 23.98