GithubHelp home page GithubHelp logo

til's Introduction

til's People

Contributors

sehyunchung avatar

til's Issues

IB?

Interface Builder

sourceViewController -> source

Implement Navigation을 진행하다가 아래 워닝을 만났다.

Screen Shot 2020-07-07 at 6 32 27

    //MARK: Actions
    @IBAction func unwindToMealList(sender: UIStoryboardSegue) {
-        if let sourceViewContoller = sender.sourceViewController as? MealViewController, let meal = sourceViewContoller.meal {
+        if let sourceViewContoller = sender.source as? MealViewController, let meal = sourceViewContoller.meal {
            // Add new meal.
            let newIndexPath = IndexPath(row: meals.count, section: 0)
            meals.append(meal)
            tableView.insertRows(at: [newIndexPath], with: .automatic)
        }
    }

chmod

  • chmod +rwx <filename> to add permissions.
  • chmod -rwx <directoryname> to remove permissions.
  • chmod +x <filename> to allow executable permissions.
  • chmod -wx <filename> to take out write and executable permissions.

vscode에서 preview mode로 파일 열리지 않게하기

vscode에서 file explorer나 search를 통해 찾은 파일을 클릭하면 탭에서 italic으로 파일명이 표시되면서 preview mode로 열리고, 같은 방식으로 다른 파일을 열면 preview mode였던 파일은 사라진다. 때때로 그래서 귀찮은 일이 생기는데, 이것을 막으려면 settings.json에 아래를 추가하면 된다.

{
  "workbench.editor.enablePreview": false,
}

...근데 이렇게 해놓고 무작정 다 열다 보면 램이 터질 수 있다...

:active on mobile safari

  1. webkit-tap-highlight-color 쓰기 -> 근데 :active 랑 동작이 다름

  2. body에 <body ontouchstart=""> 넣기

  3. 필요한 컴포넌트에 onTouchStart={() => false} 넣기

symlinks

path 의 alias 라고 생각하면 쉽다.

ln -s /PATH/TO/ORIGINAL /PATH/TO/LINK

Vertical rulers in vscode

rulers?

settings.json에 아래 코드를 추가하면,

"editor.rulers": [
  80,
  100,
  120
],

Screen Shot 2020-06-22 at 9 24 27 AM

위와 같이 80, 100, 120자 위치에 세로줄이 생긴다.
안 보이던 게 보이는 건 역시 좋은 일이다.

customization

세로줄의 컬러를 아래와 같이 커스텀 할 수도 있다.

"workbench.colorCustomizations": {
    "editorRuler.foreground": "#ff4081"
}

References

Declaring Global Variables in TypeScript

daum 주소검색등 window에 뭔가 끼워넣는 외부 기능 사용시, window.someApi등으로 호출하게 될 때가 있는데, TS에서 당연히 Property 'someApi' does not exist on type 'Window & typeof globalThis'. 라고 뭐라고 한다. 요걸 해결하기 위해 보통은:

(window as any).someApi

혹은

(<any>window).someApi

를 쓰라고 하는데 아래가 더 나은 것 같다.

declare global {
  interface Window {
    someApi: any; // 혹시 타입 정의를 제공해준다면 somApiType
  }
}

요게 되는 것은 interface는 merging이 되기 때문.

Ref.

https://mariusschulz.com/blog/declaring-global-variables-in-typescript

asdf nodejs

  1. asdf를 설치한다.
    brew install asdf
  2. gpg를 설치한다.
    brew install gpg
  3. asdf nodejs plugin을 설치한다.
    asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git
  4. nodejs release team의 gpg key를 추가한다.
    bash -c '${ASDF_DATA_DIR:=$HOME/.asdf}/plugins/nodejs/bin/import-release-team-keyring'
  5. nvm등 사용중이던 vm이 있다면 호환성을 위해 ~/.asdfrc에 아래를 추가한다.
    legacy_version_file = yes
  6. 됫다.

how to uninstall node

https://reactgo.com/uninstall-node-npm-from-macos/

vscode가 포맷팅 하면서 자꾸 jsx에 빈칸을 넣으면

원인

.jsx 파일의 File AssociationBabel JavaScript로 되어있어서 생기는 문제.

해결 1

화면 하단의 language mode 영역을 클릭 -> JavaScript React로 바꾸면 해결

Screen Shot 2020-06-28 at 17 52 41

해결 2

물론 settings.json에서 바꿀수도 있다.

"files.associations": {
  "*.jsx": "javascriptreact"
}

Array._proto__.length

js array는 object이고 length 프로퍼티를 갖고 있다. 그래서 아래가 가능.

const {length, [0]: first, [length - 1]: last} = [1, 2, 3];

console.log(first, last);  // 1 3

주의: length를 선언해두지 않으면 length - 1을 알 수 없고 lastundefined 되어버림.

vscode에서 swift language server 돌리기

xcode에선 vim key 바인딩, hover action 등등이 간단하게 안되는 것 같아 vscode에 개발 환경 꾸미는 게 가능할까 알아보았다.

  1. 원하는 위치에 sourcekit-lsp를 클론 받는다.
  2. $ cd sourcekit-lst/Editors/vscode
  3. $ npm run createDevPackage
  4. $ code --install-extension out/sourcekit-lsp-vscode-dev.vsix
  5. 공식엔 여기까지 하면 된다고 나와있긴 한데, vscode에서 Starting client failed Launching server using command sourcekit-lsp failed. 라며 에러가 발생했다.
  6. $ xcrun -f sourcekit-lspsourcekit-lsp가 설치된 경로를 알아내서 복사한다.
  7. vscode settings.json에 아래를 추가한다.
  8.   "sourcekit-lsp.serverPath": "<경로>"
  9. vscode를 reload 한다.

  10. Screen Shot 2020-06-28 at 14 34 30
  11. https://marketplace.visualstudio.com/items?itemName=vknabel.vscode-swiftlint 도 설치하면 좋다 카더라.

React.memo vs useMemo

React.memo

  • Higher order component.
  • prop change만을 체크함. 감싼 컴포넌트 안에 useState, useContext등이 있다면, 역시 해당 state 변경에 따라 rerender됨.

useMemo

  • Hook.
  • deps array에 포함된 deps가 변경되지 않으면 memoized value를 반환하는 함수.

fix firefox color render

?

firefox의 컬러가 뭔가 좀 더 채도가 높게 렌더링 되는 경향이 있다.

  1. chrome

Screen Shot 2020-07-27 at 4 00 39 PM

  1. safari

Screen Shot 2020-07-27 at 4 01 59 PM

  1. firefox

Screen Shot 2020-07-27 at 4 03 52 PM

요걸 없애려면?

!

  1. 일단 firefox의 주소창에 about:config를 입력해 신비의 세계로 들어가서,
  2. 신비의 세계 검색창에 color_management를 쳐보면 아래와 같은 설정값들을 볼 수 있다. 이중에서,
    Screen Shot 2020-07-27 at 4 16 53 PM
  3. gfx.color_management.mode1로 바꾼다.
  4. gfx.color_management.enablev4true로 바꾼다.

  5. Screen Shot 2020-07-27 at 4 19 46 PM

이것들이 뭐냐?

  1. gfx.color_management.mode:
    • 0: Color management disabled.
    • 1: Full color management.
    • 2: Color management applied only to tagged images.
  2. gfx.color_management.enablev4:
    • 찾는 중

Refs

Xcode 프로젝트의 Team을 바꾸려면

애플 디벨로퍼 프로그램에 기존 xcode에 등록되어있던 것과 다른 apple id를 사용하게 되어, 등록되어있던 Team을 바꿀 일이 생겨서 알아보았다. 아래와 같이 간단하게 해결할 수 있었음.

Screen Shot 2020-06-27 at 20 02 47

Config Github CLI

  1. default editor가 nano로 되어있어 불편하다. vim으로 바꾸려면?

    gh config set editor vim
  2. pr 시 default base가 master로 되어있어 불편하다. develop으로 바꾸려면?

    gh pr create --base develop

Reference

google fonts에서 특정 캐릭터만 불러오기

google fonts를 url로 불러오는 방식으로 사용시 unicode-range를 사용할 수 없다.
query string 옵션으로 subset 혹은 text를 줄 수 있다.

subset

subset은 언어 기준으로, 영문에만 특정 폰트를 적용하고 싶을 경우 사용한다. Roboto를 영문과 숫자에만 쓰고 싶다면?
https://fonts.googleapis.com/css2?family=Roboto&subset=latin 이라고 하면 된다.

text

text가 좀 더 재밌는데, 개별 캐릭터를 옵션으로 추가할 수 있다. 예를 들어 Roboto를 0과 1에만 쓰고 싶다면?

https://fonts.googleapis.com/css2?family=Roboto&text=01 으로 요청하면 된다.

"Could not insert new outlet connection" error

문제

FoodTracker를 신나게 만드는 중이었는데, save 버튼을 MealViewController에 연결시키려던 순간!

위와 같은 메시지를 보여주면서 안되는 경우가 생겼다.

해결

  1. cmd+shift+K를 눌러 product를 clean 한다.
  2. cmd+R로 build + run을 한다.
  3. 한 번 해본다.
  4. 안되면 xcode를 재시작한다.

UIImagePickerControllerOriginalImage

FoodTracker 예제 중 Work with View Controllers 튜토리얼에 버그... 는 아니고 옛날 자료라서 지금 안돌아가는 게 있었다.

링크를 찾아 아래와 같이 해결

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        // The info dictionary may contain multiple representations of the image. You want to use the original.
-        guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
+        guard let selectedImage = info[.originalImage] as? UIImage else {
            fatalError("Expected a dictionary containing as image, but was provided the following: \(info)")
        }

        // Set photoImageView to display the selected image.
        photoImageView.image = selectedImage

        // Dismiss the picker.
        dismiss(animated: true, completion: nil)
    }

flex

flex

flex-grow, flex-shrink, + flex-basis의 shorthand이다.

syntax

  • One-value syntax:
    the value must be one of:
    • a <number>: In this case it is interpreted as flex: <number> 1 0; the <flex-shrink> value is assumed to be 1 and the <flex-basis> value is assumed to be 0.
    • one of the keywords: none, auto, or initial.
  • Two-value syntax:
    the first value must be a <number> and it is interpreted as <flex-grow>. The second value must be one of:
    • a <number>: then it is interpreted as <flex-shrink>.
    • a valid value for width: then it is interpreted as <flex-basis>.
  • Three-value syntax:
    the values must be in the following order:
    • a <number> for <flex-grow>.
    • a <number> for <flex-shrink>.
    • a valid value for width for <flex-basis>.

type argument default value

예를 들어, 첫번째 arg는 보통 string이고 두번째 arg는 보통 number인데 아닐 수도 있고 두번째 arg가 있을 수도 없을 수도 있는 함수의 타입을 정의한다면 아래와 같이 선언할 수 있을 것이다.

type ExampleFn<T, U> = (arg0: T, arg1?: U) => SomeReturnType;

근데 쓸 때 마다 아래와 같이 하기는 매우 귀찮은 일이다.

const implmentedFn1: ExampleFn<string, number> = (val: string) => /* ... */

그래서 ts는 type argument에도 default value를 정해놓을 수 있는데, 함수 default value랑 동일한 형태로, 아래와 같이 하면 된다.

type ExampleFn<T = string, U = number> = (arg0: T, arg1?: U) => SomeReturnType;

이제부턴 굳이 명시할 필요가 생기지 않으면 그냥 편하게 쓸 수 있다.

const implmentedFn2: ExampleFn = (val: string) => /* ... */

그러고보니 아예 arg에 타입 어노테이션을 안해도 된다.

const implmentedFn3: ExampleFn = (val) => /* ... */

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.