This file contains 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 { useState, useEffect } from 'react'; | |
import { ethers } from "ethers"; | |
import { bufferToHex } from "ethereumjs-util"; | |
import { encrypt as metamaskEncrypt } from '@metamask/eth-sig-util'; | |
function Example() { | |
const [encryptedMessage, setEncryptedMessage] = useState(null); | |
const [encryptionPublicKey, setEncryptionPublicKey] = useState(null); | |
const [decryptedString, setDecryptedString] = useState(null); | |
const [accounts, setAccounts] = useState(null); |
This file contains 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 | |
class Animal: NSCopying { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
func copy(with zone: NSZone? = nil) -> Any { |
This file contains 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
class Animal { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
} | |
let animal = Animal(name: "Lion") | |
let animalCopy = animal |
This file contains 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
enum FruitType: String { | |
case fuji, gala, crispin | |
} | |
struct Fruit { | |
var type: FruitType | |
let expirationDate: Date | |
} | |
var apple = Fruit(type: .fuji, expirationDate: Date()) |
This file contains 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
class TreeNode: Hashable { | |
var val: Int | |
var left: TreeNode? | |
var right: TreeNode? | |
init(_ val: Int, _ left: TreeNode? = nil, _ right: TreeNode? = nil) { | |
self.val = val | |
self.left = left | |
self.right = right | |
} |
This file contains 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
func findSmallestKth(_ array: [Int], _ k: Int) -> Int { | |
let pivot = array.first! | |
let arraySmallerThanPivot = array.dropFirst().filter {$0 < pivot} | |
let arrayLargerThanPivot = array.dropFirst().filter { $0 > pivot } | |
let newArray = arraySmallerThanPivot + [Int(pivot)] + arrayLargerThanPivot | |
let positionOfPivot = array.count > 1 ? arraySmallerThanPivot.count : 0 | |
if k-1 == positionOfPivot { | |
return newArray[positionOfPivot] | |
} else if k-1 > positionOfPivot { | |
return findSmallestKth(arrayLargerThanPivot, k-1-positionOfPivot) |
This file contains 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
func quickSort<T: Comparable>(array: [T]) -> [T] { | |
guard !array.isEmpty else { return [] } | |
let pivot = array.first! | |
let arrayLessThanOrEqualToPivot = array.dropFirst().filter { $0 <= pivot } | |
let arrayGreaterThanOrEqualToPivot = array.dropFirst().filter { $0 > pivot } | |
return quickSort(arrayLessThanOrEqualToPivot) + [Int(pivot)] + quickSort(arrayGreaterThanOrEqualToPivot) | |
} |
This file contains 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
func isPalindrome(_ word: String) -> Bool { | |
let word = word.lowercased().characters.filter{ $0 != " " } | |
for (i, character) in word.enumerated() { | |
if character != word[word.count-i-1] { | |
return false | |
} | |
} | |
return true | |
} |
This file contains 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
// | |
// ActivityIndicator.swift | |
// | |
// Created by Ali Mir on 11/17/16. | |
// Copyright © 2016 com.AliMir. All rights reserved. | |
// | |
import UIKit | |
struct ActivityIndicator { |