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
#include "LaunchTimeMeasurer.h" | |
#include <sys/sysctl.h> | |
#include <sys/unistd.h> | |
double processUptime() { | |
struct timeval currentTime; // current time returned by gettimeofday | |
struct kinfo_proc processInfo; // information about current process returned by sysctl | |
size_t processInfoSize = sizeof(processInfo); // information's size | |
int mib[] = { // Management Information Base | |
CTL_KERN, // "high kernel": proc, limits |
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 UIKit | |
class LaunchTimeMeasurer { | |
private let pid = ProcessInfo().processIdentifier | |
private var currentTime = timeval(tv_sec: 0, tv_usec: 0) | |
private var bootTime = timeval() | |
private var size = MemoryLayout<kinfo_proc>.stride | |
private var mib: [Int32] | |
init() { |
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
typealias A = ArraySlice<Bool> | |
func sieveOfEratosthenes(limit: Int) -> [Int] { | |
var possibles = A(repeating: true, count: limit + 1) | |
var result = [Int]() | |
for i in 2 ... limit { | |
guard possibles[i] else { continue } | |
for j in stride(from: i * i, through: limit, by: i) { | |
possibles[j] = false | |
} | |
result.append(i) |
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 WeakList<T: AnyObject> { | |
private class WeakRef { | |
private(set) weak var value: T? | |
init(_ value: T) { | |
self.value = value | |
} | |
} | |
private var arr = [WeakRef]() |
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
public struct MLEncoderTool { | |
// The first argument is the file name | |
// The second argument is key | |
private let arguments: [String] | |
private let cryptor: MLCryptor | |
public init( | |
arguments: [String] = CommandLine.arguments, | |
cryptor: MLCryptor = MLCryptor.cryptoKit |
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 | |
import RNCryptor | |
import CryptoKit | |
public enum MLCryptor { | |
case cryptoKit | |
case rnCryptor | |
public func encrypt(data: Data, withPassword password: String) throws -> Data? { | |
switch self { |
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
extension SymmetricKey { | |
init(string keyString: String, size: SymmetricKeySize = .bits256) throws { | |
guard var keyData = keyString.data(using: .utf8) else { | |
print("Could not create base64 encoded Data from String.") | |
throw CryptoKitError.incorrectParameterSize | |
} | |
let keySizeBytes = size.bitCount / 8 | |
keyData = keyData.subdata(in: 0..<keySizeBytes) | |