From 36ed90aadc9af47132de4189d5c71c8b776c7b11 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:05:43 +0900 Subject: [PATCH 01/12] =?UTF-8?q?fix:=20=EA=B9=83=ED=97=88=EB=B8=8C=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=ED=98=B8=EC=B6=9C=20=EB=B0=A9=EC=8B=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/trigger_dispatch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/trigger_dispatch.yml b/.github/workflows/trigger_dispatch.yml index 72f3f93..f06f5b3 100644 --- a/.github/workflows/trigger_dispatch.yml +++ b/.github/workflows/trigger_dispatch.yml @@ -12,4 +12,4 @@ jobs: steps: - run: gh api /repos/1eecan/pickple-log/dispatches -f event_type='dispatch_event' env: - GITHUB_TOKEN: ${{ secrets.ACTION_TOKEN }} + GH_TOKEN: ${{ secrets.ACTION_TOKEN }} From de830fb183c7f6f82d6445278c8af1192af9a1c2 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:03:33 +0900 Subject: [PATCH 02/12] =?UTF-8?q?chore:=20=EC=9E=84=EC=8B=9C=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * github actions 테스트 목적 --- public/1eecan/recursive/index.md | 155 +++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 public/1eecan/recursive/index.md diff --git a/public/1eecan/recursive/index.md b/public/1eecan/recursive/index.md new file mode 100644 index 0000000..17c38cc --- /dev/null +++ b/public/1eecan/recursive/index.md @@ -0,0 +1,155 @@ +--- +title: 'This' +date: '2024-01-08' +spoiler: '자바스크립트의 this란?' +--- + +## Contents + +# 재귀함수 + +재귀함수는 정의 단계에서 자기 자신을 재참조 하는 함수로서, 트리, 트라이의 자동완성, dfs 기타 자료구조 및 알고리즘을 풀 때 빼놓을 수 없는 개념이다. + +재귀함수를 그동안 제대로 이해하려고 하지 않고, 어물쩡~~ 저물쩡~~ 예제코드가 어쩌구~~ 뭐쩌구~~ 하면서 넘어갔지만 더이상은 안되겠다는 생각이 들어서 오늘 정리를 한번 해보려고 한다. +![](https://velog.velcdn.com/images/busybusyworld/post/80b36e61-adc0-4449-b94e-0b2652a44e5e/image.png) + +> 더는 미룰 수 없다. + +# 재귀함수의 구성 + +재귀함수는 두가지의 부분으로 구분 할 수 있다. + +1. 재귀를 하면서 원하는 요구를 수행하는 부분 +2. 종료 조건을 표시한 부분 + +여기서 재귀함수를 이미 알고있는 사람은 1~10까지 더하는 함수를 재귀적으로 나타내어 보자. 재귀함수를 잘 모르는 사람은 아래의 코드를 확인해보자. + +```js +//일반 함수로 구현 +function recursive_plus(num, sum) { + //재귀함수가 끝나는 조건을 표시 + if (num == 0) return sum; + //재귀를 하면서 실행될 로직 + sum += num; + //자기 자신을 다시 쓰는, 재귀를 하는 부분 + return recursive_plus(num - 1, sum); +} +console.log(recursive_plus(10, 0)); //55 + +//사실 이렇게도 할 수 있다. +function recursive_plus(num, sum) { + if (num <= 1) return num; + return num + recursive_plus(num - 1, sum); +} + +//클래스로 구현 +class recursive_plus { + constructor() { + this.sum = 0; + } + recursive_logic(num) { + //재귀함수가 끝나는 조건을 표시 + if (num == 0) return this.sum; + //재귀를 하면서 실행될 로직 + this.sum += num--; + //자기 자신을 다시 쓰는, 재귀를 하는 부분 + this.recursive_logic(num); + } +} +const SUM = new recursive_plus(); +SUM.recursive_logic(10); +console.log(SUM.sum); //55 +``` + +이런 식으로 작성을 할 수 있다. + +재귀함수를 실행하면 지역변수, 반환주소값, 매개변수가 콜스택에 차례차례 쌓이게 된다. +![](https://velog.velcdn.com/images/busybusyworld/post/c8ae6dec-75e5-4987-bf0f-634c5382cb99/image.png) +재귀함수가 실행될때, 콜스택이란 곳에 함수가 차곡차곡 push되어서 종료조건까지 실행이 끝나면 하나씩 pop된다고 생각하면 된다. + +이해를 편하게 하기위해, 위의 두번째 더하기 함수가 + +```js +return num+(num-1)+(num-2)+(num-3)+...+2+1; +``` + +이렇게 동작한다고 보면 된다. + +## 앞구르기~ 뒷구르기~ + +재귀함수도 재귀함수를 앞에 둘 수도 있고, 뒤에 둘 수 있다. + +```js +//종료조건에 닿으면 재귀 종료 +function recursive_plus_front(num, sum) { + if (num <= 1) return num; + return num + recursive_plus_front(num - 1, sum); +} +//종료조건까지 재귀 실행 +function recursive_plus_back(num, sum) { + if (num > 1) return num + recursive_plus_back(num - 1, sum); + return 1; +} +console.log(recursive_plus_front(10, 0)); //55 +console.log(recursive_plus_back(10, 0)); //55 +``` + +취향과 상황에 맞게 골라드시면 되겠습니다. 아니 그냥 둘 다 연습을 하십셔 + +## 종료조건 정의 + +여기서 중요한 부분은 종료부분이라고 생각을 한다. +자기가 어떤 조건을 만족할 때 재귀를 종료하고 return을 뭘 시킬지를 생각을 해보는게 좋을 것이다. + +만약 그렇지 않는다면 꼬리에 꼬리를 무는 함수... +꼬꼬무 함수의 탄생을 마주하게 될것이다. +![](https://velog.velcdn.com/images/busybusyworld/post/5eeae37d-93c9-4260-a007-d36e9db3fbaa/image.png) + +> 종료조건을 잘 작성하지 못한다면 무한루프에 빠질 수 있다. + +## 종료조건 만들기 + +그리고 이럴 때 재귀를 종료합니다~~ 라고만 하면 안되고, 함수안에서 다시 함수를 부를때, 인자가 변화를 해야한다. 위의 함수에서는 num을 계속 1씩 빼면서 종료조건에 닿게 만들어준다. + +# 꼬리재귀 + +tail_call recursive function이라고 부르는데, 일반재귀함수와 다른점이 있다. +연산부를 바로 리턴에 보내버린다는 점인데 아래의 코드를 확인해보자. + +```js +let t1 = performance.now(); +function recursive_plus(num, sum) { + if (num == 1) return num; + sum += num; + return num + recursive_plus(num - 1, sum); +} +let t2 = performance.now(); + +let t3 = performance.now(); +function tail_call_recursive_plus(num, sum) { + if (num == 1) return sum + 1; + return tail_call_recursive_plus(num - 1, sum + num); +} +let t4 = performance.now(); +console.log(recursive_plus(100, 0), `time : ${t2 - t1}ms`); +console.log(tail_call_recursive_plus(100, 0), `time : ${t4 - t3}ms`); +``` + +실행을 해보면 속도차이가 10배 넘게 차이가 나는것을 알 수 있다. +메모리를 덜 사용한다고 한다. + +# 사실은 반복문 써도 똑같음 + +재귀함수가 당장은 필요하지 않다고 생각할 수 있다. 알고리즘 문제에서 사용하는거면 몰라도, 콜스택이 흘러넘치는 문제(`스택오버플로우`)를 감수하면서까지 코드를 짤 때, 반복문 대신에 재귀를 사용할 필요가 있을까? + +내 생각에 우리는 결국 나중에 규모가 점점 커지는 프로젝트들을 할텐데, 조금 더 코드를 직관적이고, 간결하게 알아볼 수 있게 해주는데 의의가 있는것 같다. 당장에 dfs를 재귀로 구현한 코드만 보더라도 재귀에 익숙하다면 지금 어떤 코드를 짜버린건지 이해를 하기가 쉽다. + +코딩을 하다 보면 콜백함수도 자주 넣게 되는데, 이런, 함수와 함수의 상호작용을 다루는 부분도 재귀함수와 비슷한 부분이 많은 것 같다. 실용적인 부분은 차치하더라도, 조금 더 프로그래머처럼 사고하는데 그 의미가 있다고 생각한다! + +![](https://velog.velcdn.com/images/busybusyworld/post/6e1a4ff9-b640-4b4e-ab7b-689f489d4fb4/image.png) + +> 그래도 재귀함수 사랑하시죠...? ^^ + +### 이미지 출처 + +https://www.geeksforgeeks.org/ From 46b987d00a20cd626795888ede3e0c31df3621f4 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:10:36 +0900 Subject: [PATCH 03/12] Update dispatch.yml --- .github/workflows/dispatch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml index 9ae2719..3202061 100644 --- a/.github/workflows/dispatch.yml +++ b/.github/workflows/dispatch.yml @@ -2,7 +2,7 @@ name: Repository Dispatch on: repository_dispatch: - types: [dispatch_event] + types: [ dispatch_event ] jobs: sync: From 4812b2c294909f4da88d6a83a468ca7689bdcdbf Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:30:31 +0900 Subject: [PATCH 04/12] Create sync.yml --- .github/workflows/sync.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 0000000..6d5798d --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,32 @@ +name: Synchronize to forked repo +on: + push: + branches: + - dev + +jobs: + sync: + name: Sync forked repo + runs-on: ubuntu-latest + + steps: + - name: Checkout main + uses: actions/checkout@v4 + with: + token: ${{ secrets.ACTION_TOKEN }} + fetch-depth: 0 + ref: dev + + - name: Add remote-url + run: | + git remote add forked-repo https://1eecan:${{ secrets.ACTION_TOKEN }}@github.com/1eecan/pickple-log + git config user.name 1eecan + git config user.email busyx2modernsociety@gmail.com + + - name: Push changes to forked-repo + run: | + git push -f forked-repo dev + + - name: Clean up + run: | + git remote remove forked-repo From a861dd62b0cf3fcc65f81603300436a12bb3a731 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:34:54 +0900 Subject: [PATCH 05/12] =?UTF-8?q?fix:=20md=ED=8C=8C=EC=9D=BC=20=EC=98=A4?= =?UTF-8?q?=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 깃헙액션 테스트 --- public/1eecan/recursive/index.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/1eecan/recursive/index.md b/public/1eecan/recursive/index.md index 17c38cc..78176b2 100644 --- a/public/1eecan/recursive/index.md +++ b/public/1eecan/recursive/index.md @@ -1,7 +1,7 @@ --- -title: 'This' -date: '2024-01-08' -spoiler: '자바스크립트의 this란?' +title: '재귀함수' +date: '2024-01-10' +spoiler: '재귀함수란?' --- ## Contents From 1d4ad53f3ec993bb97adfa8ef192999ca6446cf7 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:36:33 +0900 Subject: [PATCH 06/12] Delete .github/workflows/dispatch.yml --- .github/workflows/dispatch.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .github/workflows/dispatch.yml diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml deleted file mode 100644 index 3202061..0000000 --- a/.github/workflows/dispatch.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Repository Dispatch - -on: - repository_dispatch: - types: [ dispatch_event ] - -jobs: - sync: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Sync with Upstream - run: | - git remote add upstream https://github.com/Java-and-Script/pickple-log - git fetch upstream - git merge upstream/dev - git push origin dev From 994e7c190df4835ac78902ffb6973c6d3939ff61 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:37:00 +0900 Subject: [PATCH 07/12] Create dispatch.yml --- .github/workflows/dispatch.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/dispatch.yml diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml new file mode 100644 index 0000000..3202061 --- /dev/null +++ b/.github/workflows/dispatch.yml @@ -0,0 +1,20 @@ +name: Repository Dispatch + +on: + repository_dispatch: + types: [ dispatch_event ] + +jobs: + sync: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Sync with Upstream + run: | + git remote add upstream https://github.com/Java-and-Script/pickple-log + git fetch upstream + git merge upstream/dev + git push origin dev From ffc5bf432fb3eecd3b05e2456473e064fc665126 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 03:38:51 +0900 Subject: [PATCH 08/12] =?UTF-8?q?chore:=20=EA=B8=B0=EC=A1=B4=EC=97=90=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EB=8D=98=20dispatch=20yml=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * symc.yml로 통합 --- .github/workflows/dispatch.yml | 20 -------------------- .github/workflows/trigger_dispatch.yml | 15 --------------- 2 files changed, 35 deletions(-) delete mode 100644 .github/workflows/dispatch.yml delete mode 100644 .github/workflows/trigger_dispatch.yml diff --git a/.github/workflows/dispatch.yml b/.github/workflows/dispatch.yml deleted file mode 100644 index 3202061..0000000 --- a/.github/workflows/dispatch.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Repository Dispatch - -on: - repository_dispatch: - types: [ dispatch_event ] - -jobs: - sync: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Sync with Upstream - run: | - git remote add upstream https://github.com/Java-and-Script/pickple-log - git fetch upstream - git merge upstream/dev - git push origin dev diff --git a/.github/workflows/trigger_dispatch.yml b/.github/workflows/trigger_dispatch.yml deleted file mode 100644 index f06f5b3..0000000 --- a/.github/workflows/trigger_dispatch.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Trigger repository_dispatch - -on: - push: - branches: - - main - - dev - -jobs: - trigger: - runs-on: ubuntu-latest - steps: - - run: gh api /repos/1eecan/pickple-log/dispatches -f event_type='dispatch_event' - env: - GH_TOKEN: ${{ secrets.ACTION_TOKEN }} From b193c8e003d6b7b7a21a817f73881c9a0d7dce7d Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:27:21 +0900 Subject: [PATCH 09/12] =?UTF-8?q?feat:=20toc=20=EC=98=A4=EB=A5=B8=EC=AA=BD?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B0=B0=EC=B9=98=20=EB=B0=8F=20=EC=BB=A8?= =?UTF-8?q?=ED=85=90=EC=B8=A0=20=EC=A4=91=EC=95=99=EC=A0=95=EB=A0=AC=20?= =?UTF-8?q?=EB=B0=8F=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=A0=84=EC=B2=B4=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A1=A4=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(root)/globals.css | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/app/(root)/globals.css b/src/app/(root)/globals.css index c85cde9..8e30354 100644 --- a/src/app/(root)/globals.css +++ b/src/app/(root)/globals.css @@ -5,3 +5,31 @@ html { scroll-behavior: smooth; } +html::-webkit-scrollbar { + display: none; +} + +#contents { + display: none; +} + +#contents + ul { + position: fixed; + right: 0px; + width: 20%; + height: 100%; + font-size: 1rem; + overflow-y: scroll; + -ms-overflow-style: none; + scrollbar-width: none; +} +#contents + ul::-webkit-scrollbar { + display: none; +} + +#contents + ul li { + list-style-type: none; +} +#contents + ul a { + text-decoration: none; +} From 0d0cf8e6a97a1c487d6fdd78f39d49e8efb5aaf8 Mon Sep 17 00:00:00 2001 From: Chan Lee <120288440+1eecan@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:27:44 +0900 Subject: [PATCH 10/12] =?UTF-8?q?feat:=20=EA=B2=8C=EC=8B=9C=EA=B8=80=20?= =?UTF-8?q?=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=98=EC=8A=A4=20=EB=B0=94=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(root)/post/[slug]/ProgressBar.tsx | 44 ++++++++++++++++++++++ src/app/(root)/post/[slug]/page.tsx | 5 ++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/app/(root)/post/[slug]/ProgressBar.tsx diff --git a/src/app/(root)/post/[slug]/ProgressBar.tsx b/src/app/(root)/post/[slug]/ProgressBar.tsx new file mode 100644 index 0000000..4967cc0 --- /dev/null +++ b/src/app/(root)/post/[slug]/ProgressBar.tsx @@ -0,0 +1,44 @@ +'use client'; + +import { useEffect, useState } from 'react'; + +export default function ProgressBar() { + const [currentProgress, setCurrentProgress] = useState('0'); + + const scrollEvent = () => { + const progressBar = document.querySelector('.bar'); + + if (progressBar === null) return; + + let scrollNum = 0; + let documentHeight = 0; + + const getPercent = (scroll: number, total: number) => { + return (scroll / total) * 100; + }; + + scrollNum = document.documentElement.scrollTop; + + documentHeight = + document.documentElement.scrollHeight - + document.documentElement.clientHeight; + + setCurrentProgress(() => { + return getPercent(scrollNum, documentHeight) + '%'; + }); + }; + + useEffect(() => { + window.addEventListener('scroll', scrollEvent); + return () => window.removeEventListener('scroll', scrollEvent); + }, []); + + return ( +
+
+
+ ); +} diff --git a/src/app/(root)/post/[slug]/page.tsx b/src/app/(root)/post/[slug]/page.tsx index 8a532c1..4af69e6 100644 --- a/src/app/(root)/post/[slug]/page.tsx +++ b/src/app/(root)/post/[slug]/page.tsx @@ -1,3 +1,4 @@ +import ProgressBar from './ProgressBar'; import { getPostBySlug, getPostDatas } from '@/app/utils'; import { MDXRemote } from 'next-mdx-remote/rsc'; import rehypePrettyCode from 'rehype-pretty-code'; @@ -8,8 +9,10 @@ import remarkToc from 'remark-toc'; export default function Page({ params }: { params: { slug: string } }) { const mdxSource = getPostBySlug(params.slug).content; + return (
+ Date: Thu, 18 Jan 2024 14:02:08 +0900 Subject: [PATCH 11/12] Update sync.yml --- .github/workflows/sync.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 6d5798d..77a5acb 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -2,7 +2,7 @@ name: Synchronize to forked repo on: push: branches: - - dev + - main jobs: sync: @@ -15,17 +15,17 @@ jobs: with: token: ${{ secrets.ACTION_TOKEN }} fetch-depth: 0 - ref: dev + ref: main - name: Add remote-url run: | - git remote add forked-repo https://1eecan:${{ secrets.ACTION_TOKEN }}@github.com/1eecan/pickple-log - git config user.name 1eecan - git config user.email busyx2modernsociety@gmail.com + git remote add forked-repo https://dlwl98:${{ secrets.ACTION_TOKEN }}@github.com/dlwl98/pickple-log + git config user.name dlwl98 + git config user.email ff981113@hanyang.ac.kr - name: Push changes to forked-repo run: | - git push -f forked-repo dev + git push -f forked-repo main - name: Clean up run: | From f638d42e751762874f7f0a56992e5f211772970b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=84=EC=9A=B1?= Date: Thu, 18 Jan 2024 14:18:24 +0900 Subject: [PATCH 12/12] =?UTF-8?q?chore:=20=EC=9E=90=EB=8F=99=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=ED=99=98=EA=B2=BD=20=EA=B2=80=EC=A6=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit