Skip to content

Instantly share code, notes, and snippets.

@staticVoidMan
staticVoidMan / inspectorScripts.js
Last active January 8, 2025 06:07
Handy inspector scripts
// Change Youtube video playback speed
1. document.getElementsByClassName("video-stream html5-main-video")[0].playbackRate = 2.5
2. document.querySelector('video').playbackRate = 2.5
// I re-typed what I saw in reference 3 below,
// went to Liked videos page on YouTube[1] while logged in,
// pasted that into browser dev tools console (Google Chrome Version 97.0.4692.99 (Official Build) (x86_64)),
// pressed enter, and it seemed to do its thing, for the most part
// (when I refreshed the page, there was still 1 video remaining).
// [1] as of 2022-01-23 that’s at https://www.youtube.com/playlist?list=LL
// context: https://twitter.com/QiaochuYuan/status/1485164256970510340
// references:
@staticVoidMan
staticVoidMan / MainActorExample.swift
Last active October 15, 2023 15:13
Swift; Concurrency; MainActor; Task; Task.detached
import Foundation
@MainActor
func test() async {
print(0, Thread.isMainThread)
Task {
print(1, Thread.isMainThread)
}
@staticVoidMan
staticVoidMan / TestClosureToAsync.swift
Last active October 15, 2023 13:32
Swift; Supporting async for closure-based & combine-based functions using `withCheckedThrowingContinuation`/`withCheckedContinuation`
extension Test {
func asyncGetImageFromClosure() async throws -> UIImage {
try await withCheckedThrowingContinuation { continuation in
getImageInClosure { result in
switch result {
case let .success(image):
continuation.resume(returning: image)
case let .failure(error):
continuation.resume(throwing: error)
@staticVoidMan
staticVoidMan / 1-API.swift
Last active October 14, 2023 15:09
Swift Concurrency, Async Let, Task Group
/*
Ref: https://swiftsenpai.com/swift/understanding-task-groups
*/
import UIKit
enum ImageStyle: CaseIterable {
case small
case medium
case large
@staticVoidMan
staticVoidMan / NetworkManager+Example.swift
Last active October 10, 2023 13:39
A scalable easy-to-use Network Manager
/*
Example based on API service: `https://api.quotable.io`
*/
import Foundation
//MARK: Usage Example
let provider: QuoteProvider = QuoteAPIProvider()
Task {
@staticVoidMan
staticVoidMan / MyPublished.swift
Created October 5, 2023 16:43
Replicated Property Wrapper behavior of @published
// Ref: https://jllnmercier.medium.com/swift-propertywrapper-with-publisher-2e7132aab3e1
import Combine
@propertyWrapper
class MyPublished<T> {
var wrappedValue: T {
didSet {
subject.send(wrappedValue)
@staticVoidMan
staticVoidMan / builderPattern.swift
Last active September 22, 2023 05:33
Builder Design Pattern - Image Manipulation
/*
Refs:
- https://springframework.guru/gang-of-four-design-patterns/builder-pattern
- https://refactoring.guru/design-patterns/builder/swift/example#example-1
*/
import UIKit
enum Shape {
case circle(radius: Double)
@staticVoidMan
staticVoidMan / linkedList.swift
Last active September 14, 2023 03:53
Data Structure - Linked List
class Node<T: Equatable> {
let value: T
var next: Node<T>?
init(_ value: T, next: Node<T>? = nil) {
self.value = value
self.next = next
}
}