Skip to content

Instantly share code, notes, and snippets.

View NSEGeorge's full-sized avatar

Georgii Emelianov NSEGeorge

View GitHub Profile
@NSEGeorge
NSEGeorge / LaunchTimeMeasurer.c
Last active November 25, 2019 10:06
C function for measuring application launch time. Call it from start or end didFinishLaunchingWithOptions.
#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
@NSEGeorge
NSEGeorge / LaunchTimeMeasurer.swift
Created November 3, 2018 14:21
Swift implementation of function for measuring application launch time. Call it from start or end didFinishLaunchingWithOptions.
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() {
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)
class WeakList<T: AnyObject> {
private class WeakRef {
private(set) weak var value: T?
init(_ value: T) {
self.value = value
}
}
private var arr = [WeakRef]()
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
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 {
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)