Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Toshihiro Suzuki toshi0383

🏠
Working from home
Block or report user

Report or block toshi0383

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 0.swift
// comparing atomic operation performance
import Foundation
final class Locking {
static let shared = Locking()
private(set) var isLocked: Bool = false
private let _lock = NSLock()
View 0.swift
// comparing atomic operation performance
import Concurrency
import Foundation
final class Locking {
static let shared = Locking()
private(set) var isLocked: Bool = false
@toshi0383
toshi0383 / IsCase.stencil
Last active Nov 1, 2019
Generate useful extension when filtering enum values
View IsCase.stencil
{% for enum in types.enums %}
// MARK: {{ enum.name }}
extension {{ enum.name }} {
{% for case in enum.cases %}
{{ enum.accessLevel }} var is{{ case.name|upperFirstLetter }}: Bool {
switch self { case .{{ case.name }}: return true; default: return false; }
}
{% endfor %}
}
{% endfor %}
View do-one-loop-at-a-time-async.swift
import Foundation
let smp = DispatchSemaphore(value: 1)
let smp1 = DispatchSemaphore(value: 0)
func doSomething() {
for i in (0..<4) {
smp.wait()
print("[\(i * 3)]")
defer {
View share-and-initial-value.swift
let hotdogProperty = BehaviorSubject<String>(value: "")
Observable<Int>
.interval(1.0, scheduler: ConcurrentMainScheduler.instance)
.map { "Nice \($0)" }
.startWith("bonapetit!")
.debug("[source]")
.subscribe(onNext: { hotdogProperty.onNext($0) })
func hotdogObservable() -> Observable<String> {
return hotdogProperty.asObservable()
View combine-latest.go
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
View combine-latest.go
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
View cat.go
package main
import (
"bufio"
"fmt"
"log"
"os"
)
func main() {
View RxSmartThrottleTests.swift
import XCTest
@testable import RxSmartThrottle
final class RxSmartThrottleTests: XCTestCase {
static var allTests = [
("test_Throttle__customInterval__ExponentialBackoff", test_Throttle__customInterval__ExponentialBackoff),
("test_Throttle__customInterval__latest__false", test_Throttle__customInterval__latest__false),
("test_Throttle__customInterval__throttleUntil", test_Throttle__customInterval__throttleUntil),
]
}
View RxSmartThrottle.swift
import Foundation
import RxSwift
extension ObservableType {
/**
Returns an Observable that emits the first and the latest item emitted by the source Observable during sequential time windows of a specified duration.
This operator makes sure that no two elements are emitted in less then each consulted dueTime.
You can’t perform that action at this time.