Skip to content

Instantly share code, notes, and snippets.

View dotNetTree's full-sized avatar

SeungChul Kang dotNetTree

View GitHub Profile
declare global {
interface Window {
projectName?: {
action: (message: string) => void;
},
webkit?: {
messageHandlers?: {
projectName?: {
postMessage?: (message: any) => void
}
@dotNetTree
dotNetTree / code_spitz_90_2.kt
Last active June 10, 2022 13:30
Code Spitz 90 - 코틀린 언어편 (2) 과제
// 1. Set도 동작하게
// 2. Map도 동작하게
// 3. inline 함수에 대해 조사한 뒤 최대 반영
// 4. 어떤 클래스에 toJSON():String 메소드가 있다면 그 메소드를 통해 stringify를 하게 하시오
@Target(AnnotationTarget.PROPERTY)
annotation class Ex // 제외할 속성
@Target(AnnotationTarget.PROPERTY)
annotation class Name(val name: String) // json용 별도 이름지정
@dotNetTree
dotNetTree / code_spitz_90_1.kt
Last active June 7, 2022 01:33
Code Spitz 90 - 코틀린 언어편 (1) 과제
val trim = """[^.\d-+*/()]""".toRegex()
fun trim(v: String): String = v.replace(trim, "")
fun repMMtoP(v: String) = v.replace("--", "+")
fun repMtoPM(v: String) = v.replace("-", "+-")
val groupMD = """((?:\+|\+-)?[.\d]+)([*/])((?:\+|\+-)?[.\d]+)""".toRegex()
tailrec fun removeMultiDiv(v: String): String = groupMD.find(v).let {
if (it != null) {
val (target, left, op, right) = it.groupValues
val leftValue = left.replace("+", "").toDouble()
protocol Paper2 { func run() throws -> [Program] }
protocol AnyProgrammer {
func makeProgram() throws -> Program
}
protocol Programmer2: AnyProgrammer {
associatedtype T: Paper2
// Programmer는 Director에게 Paper를 제공 받아 Program으로 모델링 하는 메소드가 필요하다.
func setData(paper: T) throws -> Void
}
@dotNetTree
dotNetTree / regex_replace.swift
Last active June 4, 2019 06:13
string replace with regex
extension String {
var isBlank: Bool {
return self.trimmingCharacters(in: .whitespaces).isEmpty
}
func substring(_ r: Range<Int>?) -> String {
guard let r = r else { return self }
let fromIndex = self.index(self.startIndex, offsetBy: r.lowerBound)
let toIndex = self.index(self.startIndex, offsetBy: r.upperBound)
let indexRange = Range<String.Index>(uncheckedBounds: (lower: fromIndex, upper: toIndex))
return String(self[indexRange])
//
// WeakMap.swift
// dotNetTree
//
// Created by SeungChul Kang on 2018. 5. 1..
// Copyright © 2018년 motel. All rights reserved.
//
import Foundation
@dotNetTree
dotNetTree / parse.swift
Created April 21, 2018 06:06
a simple querystring parser with nesting support
func parse(qs: String) -> [String: Any]? {
guard let regex = try? NSRegularExpression.init(
pattern: "(?:[^\\[\\]]+)",
options: NSRegularExpression.Options(rawValue: 0)
) else {
return nil
}
return qs