Skip to content

Instantly share code, notes, and snippets.

View anitaa1990's full-sized avatar
🎯
Focusing

Anitaa Murthy anitaa1990

🎯
Focusing
  • Chennai
View GitHub Profile
@anitaa1990
anitaa1990 / StringExtension.swift
Last active March 31, 2018 06:15
A Swift extension class for String
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
*/
@anitaa1990
anitaa1990 / DictionaryExtension.swift
Created March 31, 2018 06:14
A Swift extension class for Dictionary
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) {
@anitaa1990
anitaa1990 / CurvedUIView.swift
Last active May 18, 2022 16:22
A Swift extension of UIView to display a curved view
import UIKit
extension UIView {
/* Usage Example
* bgView.addBottomRoundedEdge(desiredCurve: 1.5)
*/
func addBottomRoundedEdge(desiredCurve: CGFloat?) {
@anitaa1990
anitaa1990 / AES.java
Created April 6, 2018 09:06
AES Encryption - Android
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));
@anitaa1990
anitaa1990 / AES.js
Created April 6, 2018 09:06
AES Encryption - Javascript
//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,
@anitaa1990
anitaa1990 / AES.swift
Last active April 6, 2018 09:23
AES Encryption - Swift
/* 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
@anitaa1990
anitaa1990 / ViewControllerA.swift
Last active April 28, 2018 11:38
This example illustrates how to push a view controller to the top of the navigation stack
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
@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
@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
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;
}