This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Dictionary { | |
| /* | |
| * merge two dictionaries together to a single dictionary | |
| * var data1: Dictionary<String, String> = ["Fname", "Anitaa"] | |
| * var data2: Dictionary<String, String> = ["lname", "Murthy"] | |
| * var data3: data1.update(data2) | |
| * print(data3) -> ["Fname": "Anitaa", "lname" : "Murthy"] | |
| */ | |
| mutating func update(other:Dictionary) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| extension String { | |
| /* | |
| * split a string into n lines | |
| * Eg: var s: String = "This is the first line.\nThis is the second line" | |
| * print(s.lines[0]) -> This is the first line | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AES { | |
| public static String encrypt(String key, String algorithm, String value) { | |
| try { | |
| SecretKey secretKey = new SecretKeySpec(Base64.decode(key.getBytes(), Base64.NO_WRAP), "AES"); | |
| AlgorithmParameterSpec iv = new IvParameterSpec(Base64.decode(key.getBytes(), Base64.NO_WRAP)); | |
| Cipher cipher = Cipher.getInstance(algorithm); | |
| cipher.init(Cipher.ENCRYPT_MODE, secretKey, iv); | |
| return new String(Base64.encode(cipher.doFinal(value.getBytes("UTF-8")), Base64.NO_WRAP)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Sample Implementation can be found here: https://jsfiddle.net/4zb9hrxb/1890/ | |
| let key = "Q8pTgdOC7h25qKVncJlzDA==" | |
| let message = "TestAnitaa009" | |
| let base64Key = CryptoJS.enc.Base64.parse(key); | |
| var iv = base64Key | |
| let encryptedValue = CryptoJS.AES.encrypt(message, base64Key, { | |
| mode: CryptoJS.mode.CBC, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Using WebCrypto.swift. You can download it using this link: | |
| * https://github.com/etienne-martin/WebCrypto.swift | |
| */ | |
| public class AES { | |
| /* The key received from the backend: base64 encoded string | |
| * Step 1: Convert the base64 encoded string & the value to be encrypted -> to Data value type | |
| * Step 2: Convert the base64 encoded string to a hex string -> base64KeyData.map { String(format: "%02x", $0) }.joined() | |
| * Step 3: Use Webcrypto.swift to encrypt the value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class ViewController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @IBAction func handleLoginAction(_ sender: Any) { | |
| /* | |
| * This example is when we want to pop current view controller & remove it from navigation backstack | |
| * before adding a new view controller to the stack | |
| */ | |
| /* Step 1: Instantiate the new View controller. In this case: ViewControllerC */ | |
| let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) | |
| let viewControllerC = storyBoard.instantiateViewControllerWithIdentifier("ViewControllerC") as! ViewControllerC | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @IBAction func handleLoginAction(_ sender: Any) { | |
| /* | |
| * This example is when we want to pop all view controllers from navigation backstack | |
| * & add a new view controller as the root view controller to the stack | |
| */ | |
| /* Step 1: Instantiate the new View controller. In this case: ViewControllerC */ | |
| let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil) | |
| let viewControllerC = storyBoard.instantiateViewControllerWithIdentifier("ViewControllerC") as! ViewControllerC | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class NoteDiffUtil extends DiffUtil.Callback { | |
| List<Note> oldNoteList; | |
| List<Note> newNoteList; | |
| public NoteDiffUtil(List<Note> oldNoteList, List<Note> newNoteList) { | |
| this.oldNoteList = oldNoteList; | |
| this.newNoteList = newNoteList; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void addTasks(List<Note> newNotes) { | |
| NoteDiffUtil noteDiffUtil = new NoteDiffUtil(notes, newNotes); | |
| DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(noteDiffUtil); | |
| notes.clear(); | |
| notes.addAll(newNotes); | |
| diffResult.dispatchUpdatesTo(this); | |
| } |
OlderNewer