This file contains hidden or 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
/// 배열의 모든 조합 구하기 (순열) | |
/// 순서에 상관하여 같은 요소라도 순서가 다르면 다른 조합으로 처리 | |
/// - Parameters: | |
/// - arr: 제공되는 배열 | |
/// - select: 몇개의 요소를 선택해서 조합할지 결정 | |
/// - Returns: 제공된 배열에서 select 개를 선택해서 조합된 새 배열 | |
func getAllPermutations(_ arr: [Int], select: Int) -> [[Int]] { | |
var results: [[Int]] = [] | |
if select == 1 { | |
return arr.map { [$0] } |
This file contains hidden or 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
extension NullIterable<E> on Iterable<E> { | |
E? getFirstOrNull(bool test(E element)) { | |
try { | |
return this.firstWhere(test); | |
} catch (e) { | |
return null; | |
} | |
} | |
} |
This file contains hidden or 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
/// [Page] 배열에서 movies 값만 모아 가져오기. | |
extension Array where Element == Page { | |
var movies: [String] { | |
flatMap { $0.movies } | |
} | |
} | |
/// Page 샘플 | |
struct Page { | |
let movies: [String] |
This file contains hidden or 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
// from Node.js 하이 퍼포먼스 | |
var users = {}; | |
function getUser(id, next) { | |
if (users.hasOwnPropoerty(id)) { | |
if (users[id].hasOwnProperty("data")) { | |
return next(null, users[id].data); | |
} | |
// 아직 값이 없음 |
This file contains hidden or 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
class Rest { | |
static apiBaseUrl = ''; | |
static getApiHeader({withoutContentType = false} = {}) { | |
const header = {}; | |
header['reqVersion'] = 2; | |
// if (authentic) { | |
// header['Authorization'] = this.getAuthToken(); | |
// } |
This file contains hidden or 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
// extends ajax | |
$.ajax = (($oldAjax) => { | |
var df = $.Deferred(); | |
// on fail, retry by creating a new Ajax deferred | |
function check(self, status) { | |
console.log("check " + status + " => " + self.retries); | |
const shouldRetry = status != 'success' && status != 'parsererror'; | |
if (shouldRetry && self.retries > 0) { | |
setTimeout(() => { | |
console.log("retry " + self.retries); |
This file contains hidden or 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
/// 바인딩 | |
private var observations: [NSKeyValueObservation] = [] | |
private var viewModel = ExpenseViewModel() | |
// 뷰 바인딩 | |
observations = [ | |
viewModel.observe(\.price) { | |
let price = $0 ?? 0.0 | |
self.updatePriceText(with: price) | |
self.changesPublisher.onNext(1) |
This file contains hidden or 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
class ExpenseViewModel: NSObject { | |
@objc dynamic var price = -1.0 | |
@objc dynamic var title = "" | |
@objc dynamic var text: String? = nil | |
} |
This file contains hidden or 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
extension NSObjectProtocol where Self: NSObject { | |
func observe<Value>(_ keyPath: KeyPath<Self, Value>, | |
onChange: @escaping (Value?) -> Void) -> NSKeyValueObservation { | |
return observe(keyPath, options: [.initial, .new]) { _, change in | |
onChange(change.newValue) | |
} | |
} | |
func bind<Value, Target>(_ sourceKeyPath: KeyPath<Self, Value>, |
This file contains hidden or 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
Scheduler scheduler = Schedulers.newThread(); | |
Scheduler.Worker worker = scheduler.createWorker(); | |
worker.schedule(() -> { | |
result += "First_Action"; | |
worker.unsubscribe(); | |
}); | |
worker.schedule(() -> result += "Second_Action"); | |
Assert.assertTrue(result.equals("First_Action")); |