Skip to content

Instantly share code, notes, and snippets.

@boraseoksoon
boraseoksoon / delay_compatibility.swift
Last active December 16, 2022 21:06
delay prior to iOS 16
import Foundation
// < iOS 16
var task: Task<(), Never>?
func delay(seconds: Int = 1,
operation: @escaping () -> Void) {
task = Task {
do {
@boraseoksoon
boraseoksoon / thread_pool.swift
Created December 16, 2022 06:21
cooperative thread pool test code
import Foundation
// reference: https://stackoverflow.com/questions/67978028/maximum-number-of-threads-with-async-await-task-groups
func run() async {
await withTaskGroup(of: Void.self) { group in
for i in 0 ..< 32 {
group.addTask {
print(await fire(i))
}
@boraseoksoon
boraseoksoon / delay.swift
Last active December 17, 2022 01:56
delay
import Foundation
// >= iOS 16
var task: Task<(), Never>?
func delay(interval: Duration = .seconds(1),
operation: @escaping () -> Void) {
task = Task {
do {
@boraseoksoon
boraseoksoon / debounce.swift
Last active December 16, 2022 21:11
debounce
import Foundation
// >= iOS 16
var task: Task<(), Never>?
func debounce(interval: Duration = .nanoseconds(10000),
operation: @escaping () -> Void) {
task?.cancel()
@boraseoksoon
boraseoksoon / debounce-throttle.swift
Created December 14, 2022 05:30 — forked from simme/debounce-throttle.swift
Swift 3 debounce & throttle
//
// debounce-throttle.swift
//
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
//
import Foundation
extension TimeInterval {
@boraseoksoon
boraseoksoon / operator_overload.swift
Created November 20, 2022 15:44
Swift operator overloading example (pipe)
import Foundation
precedencegroup ForwardPipe {
associativity: left
}
infix operator |> : ForwardPipe
func |> <V, F>(v: V, f: ((V) -> F)) -> F {
f(v)
@boraseoksoon
boraseoksoon / test.ts
Last active October 2, 2022 21:07
typescript
export default "123";
@boraseoksoon
boraseoksoon / macro.clj
Last active September 22, 2022 01:22
study note for Clojure macro
;; Clojure macro & homoiconicity (LISP) for newbies
;;
;; This is personal study note
;;
;; Disclaimer:
;; Here I am trying to guide the high level of overview of macro & homoiconicity based on Clojure.
;; I cannot say these will be 100% accurate, since I am also still in the middle of getting LISP and Clojure,
;; but at least I believe it could portray the big picture
;; rather than the technical detail inside, providing links of blogs and articles I found useful.
;; Please do your own research when in doubt if interested further by using this as the guidance.
@boraseoksoon
boraseoksoon / invert_tree.cljs
Last active September 15, 2022 21:04
Invert binary in Clojure
;; invert binary tree: https://leetcode.com/problems/invert-binary-tree/
;; Given the root of a binary tree, invert the tree, and return its root.
;; Input: root = [4,2,7,1,3,6,9]
;; Output: [4,7,2,9,6,3,1]
;; Input: root = [2,1,3]
;; Output: [2,3,1]
;; Input: root = []
@boraseoksoon
boraseoksoon / pascal_triangle.clj
Last active September 12, 2022 07:14
The Pascal Triangle in Clojure
;; The Pascal Triangle: https://www.hackerrank.com/challenges/pascals-triangle/problem?isFullScreen=true
;; For a given integer , print the first rows of Pascal's Triangle.
;; Print each row with each value separated by a single space.
;; The value at the row and column of the triangle is equal to where indexing starts from.
;; These values are the binomial coefficients.
;; The Pascal Triangle
;; 1
;; 1 1