Skip to content

Instantly share code, notes, and snippets.

@willie-hung
willie-hung / concurrency.swift
Created September 26, 2023 16:50
 iOS Interview Prep 7- Async/Await
do {
// 1. Call the method
let images = try await fetchImages()
// 2. Fetch images method returns
// 3. Call the resize method
let resizedImages = try await resizeImages(images)
// 4. Resize method returns
print("Fetched \(images.count) images.")
@willie-hung
willie-hung / closure.swift
Created September 26, 2023 16:49
 iOS Interview Prep 7- Async/Await
// 1. Call the method
fetchImages { result in
// 3. The asynchronous method returns
switch result {
case .success(let images):
print("Fetched \(images.count) images.")
// 4. Call the resize method
resizeImages(images) { result in
// 6. Resize method returns
@willie-hung
willie-hung / singleton.swift
Created September 25, 2023 20:53
 iOS Interview Prep 4- Singleton pattern
class DatabaseManager {
static let databaseObj = DatabaseManager()
private init() {
}
func checkDatabaseAccess(user: String) {
if user == ("Sung-Jie") {
print("Access Granted!")
} else {
┌───────────────────────────┐
┌─>│ timers │
│ └─────────────┬─────────────┘
│ ┌─────────────┴─────────────┐
│ │ pending callbacks │
│ └─────────────┬─────────────┘
│ ┌─────────────┴─────────────┐
│ │ idle, prepare │
│ └─────────────┬─────────────┘ ┌───────────────┐
│ ┌─────────────┴─────────────┐ │ incoming: │
@willie-hung
willie-hung / index.js
Created August 3, 2023 19:35
post_33
const firstFunction = () => {
console.log("Hello from the first function");
};
const secondFunction = () => {
setTimeout(() => {
console.log("Hello from the second function");
}, 1000);
};
@willie-hung
willie-hung / index.js
Created August 3, 2023 18:53
post_33
const firstFunction = () => {
console.log("Hello from the first function");
};
const secondFunction = () => {
console.log("Hello from the second function");
};
firstFunction();
secondFunction();
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`toUpperCase 1`] = `"FOOBAR"`;
export const toUpperCase = (str: string) => str.toUpperCase();
if (import.meta.vitest) {
const { it, expect } = import.meta.vitest;
it("toUpperCase", () => {
const result = toUpperCase("foobar");
expect(result).toMatchSnapshot();
});
}
.
└── vitest-demo/
└── coverage/
└── index.ts.html
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
includeSource: ["src/**/*.{js,ts}"],
coverage: {
reporter: ["text", "html"],
},
},
});