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
#!/usr/bin/env xcrun --sdk macosx swift | |
/// Run: swift answer\[1\].swift | |
var tokens: [String] = [] | |
// O(1) | |
func ingest(_ input: String) { | |
tokens.append(input) | |
} |
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
#!/usr/bin/env xcrun --sdk macosx swift | |
/// Run: swift answer\[2\].swift | |
import Foundation | |
class Cacher { | |
private let capacity: Int | |
private var cache: [String: (value: Int, weight: Double, timestamp: TimeInterval)] = [:] | |
private var scoreHeap: [(score: Double, counter: Int, key: String)] = [] |
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
#!/usr/bin/env xcrun --sdk macosx swift | |
/// Run: swift answer\[3\].swift | |
import Foundation | |
enum CustomError: Error { | |
case msg(String) | |
} |
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
#!/usr/bin/env xcrun --sdk macosx swift | |
/// Run: swift answer\[1\].swift | |
var tokens: [String] = [] | |
// O(1) | |
func ingest(_ input: String) { | |
tokens.append(input) | |
} |
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 <MachOKit/MachOKit.h> | |
#import "BinaryHashUtils.h" | |
@implementation BinaryHashUtils | |
+(nullable NSString*) coreAppHashOfFileAtPath:(NSString*)path hasherAlg:(HasherAlg)hasherAlg { | |
NSURL* url = [NSURL fileURLWithPath:path]; | |
if (url == nil) return nil; | |
MKMemoryMap* memoryMap = [MKMemoryMap memoryMapWithContentsOfFile:url error:nil]; |
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 SwiftUI | |
import Combine | |
struct MVVMView: View { | |
@StateObject var viewModel: MVVMViewModel = MVVMViewModel() | |
var body: some View { | |
ZStack { | |
Color.green.opacity(0.5) |
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
go mod edit -module {NEW_MODULE_NAME} | |
-- rename all imported module | |
find . -type f -name '*.go' \ | |
-exec sed -i -e 's,{OLD_MODULE},{NEW_MODULE},g' {} \; |
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
struct ContentView: View { | |
@State private var text: String = "Test" | |
@State private var tempText: String = "Last message" | |
var body: some View { | |
VStack { | |
Text(tempText) | |
.frame(width: 300, height: 50, alignment: .topLeading) | |
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 | |
import CryptoKit | |
let data = "KEK! LOL!" | |
func generatePrivateKey() -> P256.KeyAgreement.PrivateKey { | |
let privateKey = P256.KeyAgreement.PrivateKey() | |
return privateKey | |
} |