다른 사람 질문에 답변하느라 진행해본 김에 필요한 사람이 있을듯 싶어 작성함





https://help.github.com/articles/setting-up-your-pages-site-repository/ 보고 진행했는데 간단히 요약하면


-------------------------------------------------------------------------------------------------------

1. www.xxx.kr 로 연결 하려면

1) GitHub 쪽 준비

  • 리파지토리 루트에 CNAME 라는 이름의 파일을 생성해서 www.xxx.kr 라는 내용을 추가

2) DNS 설정

  • Type: CNAME / NAME: www / value: 닉네임.github.io




-------------------------------------------------------------------------------------------------------

2. xxx.kr 로 연결 하려면

1) GitHub 쪽 준비

  • 리파지토리 루트에 CNAME 라는 이름의 파일을 생성해서 xxx.kr 라는 내용을 추가

2) DNS

  • Type: A / NAME: xxx.kr / value: 192.30.252.153
  • Type: A / NAME: xxx.kr / value: 192.30.252.154 (둘 다 추가)

3) (선택사항) 추가로 www.xxx.kr 로도 연결하려면

  • Type: CNAME / NAME: www / value: 닉네임.github.io 도 추가

-------------------------------------------------------------------------------------------------------


CloudFlare 기준 설정 후 5~10분 이내에 금방 연결 확인되었다.




hangaebal.github.io <- hangaebal.tk


GitHub API 활용 (2)

ajax 방식에서 페이지 갱신 방식으로 변경


routes/github.js 수정

  • 데이터를 직접 리턴하던 형태에서, 뷰와 데이터를 같이 리턴하도록
...
-   res.send(data);
+   res.render('github', {data: data, q: req.query.q});
...




views/github.jade 수정

  • jade를 거의 처음 사용하지만 레퍼런스 참고하니 크게 어려울 것은 없었다.
  • 뷰 코드 작성 시 태그를 열고 닫는 등의 단순 반복 타이핑이 확 줄었다.




현재까지의 코드 :
https://github.com/hangaebal/dictionary-node-express/tree/github-api2

Write a function

    class Solution { public int solution(int[] A); }


that, given a zero-indexed array A consisting of N integers,

returns the number of distinct values in array A.


Assume that:

    - N is an integer within the range [0..100,000];

    - each element of array A is an integer within the range [−1,000,000..1,000,000].


For example, given array A consisting of six elements such that:

    A[0] = 2    A[1] = 1    A[2] = 1

    A[3] = 2    A[4] = 3    A[5] = 1

the function should return 3, because there are 3 distinct values appearing in array A, namely 1, 2 and 3.


Complexity:

    - expected worst-case time complexity is O(N*log(N));

    - expected worst-case space complexity is O(N),

    beyond input storage (not counting the storage required for input arguments).


Elements of input arrays can be modified.


==============================================================


함수 작성:

    class Solution { public int solution(int[] A); }


N개의 정수로 구성된 배열 A가 주어지고, 배열 A의 값의 수를 리턴한다.


가정:

    - N은 [0..100,000] 범위의 정수;

    - 배열의 각 요소는 [−1,000,000..1,000,000] 범위의 정수


예를 들어 다음과 같은 여섯 요소로 구성된 배열 A가 주어진다면:

    A[0] = 2    A[1] = 1    A[2] = 1

    A[3] = 2    A[4] = 3    A[5] = 1

함수는 3을 리턴 해야한다, 왜냐하면 배열 A에 별개의 값이 '1, 2, 3' 3개 있기 때문이다.


복잡도:

    - 최악의 시간 복잡도는 O(N*log(N));

    - 최악의 공간 복잡도는 O(N), 입력 공간 제외


배열의 요소는 수정할 수 있다.






100%:

https://codility.com/demo/results/trainingT5QPBD-7CC/

만들던 앱을 활용해서 GitHub API 활용


네이버 백과사전 검색 API 결과가 기대했던 것과 달라서 계속 개선해나가기가 아쉬워졌다. (검색 결과가 특정 길이 이상 출력되지 않고 링크로 직접 가서 확인해야 한다든지..)
다른 API 중에 괜찮은 게 없을까 찾다가 GitHub API를 선택했다.

리파지토리 검색 API 적용



app.js 에 routes 추가
...
app.use('/github', require('./routes/github'));
...



routes/github.js 파일 생성

views/github.jade 파일 생성

현재까지의 소스:
https://github.com/hangaebal/dictionary-node-express/tree/github-api1

뷰 적용 및 API 결과 처리

  1. XML parser 설치
    • 네이버 API가 xml 형태로만 리턴하므로 XML 처리 라이브러리 설치
    • npm install --save xml2js

  2. 뷰 수정
    • public/stylesheets/style.css (기존 css 제거)

    • layout.jade (bootstrap 사용을 위해 div.container 추가)

    • dictionary.jade (검색어 입력 부분과 ajax 호출 부분 추가)

  3. dictionary.js 수정
현재까지의 코드 : https://github.com/hangaebal/dictionary-node-express/tree/blog3


+ Recent posts