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
/// ๋ฐ์ธ๋ฉ | |
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
// 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
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
// 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
/// [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
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
/// ๋ฐฐ์ด์ ๋ชจ๋ ์กฐํฉ ๊ตฌํ๊ธฐ (์์ด) | |
/// ์์์ ์๊ดํ์ฌ ๊ฐ์ ์์๋ผ๋ ์์๊ฐ ๋ค๋ฅด๋ฉด ๋ค๋ฅธ ์กฐํฉ์ผ๋ก ์ฒ๋ฆฌ | |
/// - 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 Int { | |
/// ์ซ์ ๋ฒ์์ ๋ฐ๋ผ ํ ์คํธ ํ์ | |
func readableCount() -> String { | |
let formatter = NumberFormatter() | |
formatter.numberStyle = .decimal | |
formatter.groupingSeparator = "" | |
formatter.maximumFractionDigits = 1 | |
switch self { | |
case _ where self < 1000: | |
return "\(self)" |
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 getPermutations(_ arr: [Book], select: Int) -> [[Book]] { | |
var results: [[Book]] = [] | |
if select == 1 { | |
return arr.map { [$0] } |