Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

Commit

Permalink
Add archived posts and modify README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ejolie committed May 18, 2019
1 parent df32110 commit e0f36a0
Show file tree
Hide file tree
Showing 11 changed files with 660 additions and 49 deletions.
37 changes: 3 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
# ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป TIL
[![Netlify Status](https://api.netlify.com/api/v1/badges/c4cf4049-2e26-4c39-a960-53e952428b7b/deploy-status)](https://app.netlify.com/sites/todayejlearned/deploys)

This repository is for the things I learned today.

The website for this repo was generated by [docsify.js](https://docsify.js.org/#/) and deployed by [netlify](https://todayejlearned.netlify.com).

## Getting started

### Prerequisites

First, clone this repo.
```
git clone https://github.com/ejolie/TIL.git
```

### Install

It is recommended to install `docsify-cli` globally, which helps initializing and previewing the website locally.
```bash
npm i docsify-cli -g
```

## Preview
Change directory to `docs/` directory and run the local server with `docsify serve`.

You can preview your site in your browser on `http://localhost:3000`.

```bash
cd docs
docsify serve docs
```
[![Netlify Status](https://api.netlify.com/api/v1/badges/c4cf4049-2e26-4c39-a960-53e952428b7b/deploy-status)](https://app.netlify.com/sites/todayejlearned/deploys)

## Deployment
I recommend you to read an official document of [docsify.js](https://docsify.js.org/#/deploy).
์˜ค๋Š˜ ๋ฐฐ์šด ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๋Š” ์ €์žฅ์†Œ์ž…๋‹ˆ๋‹ค.

You can deploy files to GitHub Pages, Netlify, etc.
์ด ์ €์žฅ์†Œ๋Š” [docsify.js](https://docsify.js.org/#/)๋ฅผ ์ด์šฉํ•ด ์›น ์‚ฌ์ดํŠธ๋กœ ๋งŒ๋“ค์–ด์กŒ์œผ๋ฉฐ [netlify](https://todayejlearned.netlify.com)๋กœ ๋ฐฐํฌ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

## Screenshot

<img src="./assets/main.png" alt="TIL - main" width="800">

<img src="./assets/detail.png" alt="TIL - detail" width="800">

4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Today I Learned
# Today I Learned

>:pencil2: ์˜ค๋Š˜ ๋ฐฐ์šด ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
> :pencil2: ๊ฐ•์˜, ๋ธ”๋กœ๊ทธ, ๊ณต์‹ ๋ฌธ์„œ ๋“ฑ์„ ๋ณด๊ณ  ๋ฐฐ์šด ๋‚ด์šฉ์„ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.
12 changes: 11 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

- ๋ถ€์ŠคํŠธ์ฝ”์Šค : ์›น ํ”„๋กœ๊ทธ๋ž˜๋ฐ
- [HTTP ํ”„๋กœํ† ์ฝœ์ด๋ž€?](/web/boost-http-protocol.md)
- [๋ธŒ๋ผ์šฐ์ €์˜ ๋™์ž‘](/web/boost-browser.md)

- :nail_care: CSS, Sass

Expand Down Expand Up @@ -66,8 +65,15 @@
- [State ์˜ฌ๋ฆฌ๊ธฐ](/react/lifting-state-up.md)
- [ํ•ฉ์„ฑ(Composition) vs ์ƒ์†(Inheritance)](/react/composition-vs-inheritance.md)

- :package: Redux

- ์ƒํ™œ์ฝ”๋”ฉ
- [Redux ์†Œ๊ฐœ](/redux/ot-redux/ot-redux-1.md)

- :green_apple: Vue

- [Vue.js ์ž…๋ฌธ์„œ](/vue/intro.md)

- :snake: Python

- [ํŒŒ์ด์ฌ ์‹ค์ˆ˜ ๋น„๊ต](/python/comparing-float.md)
Expand All @@ -76,6 +82,10 @@

- :tangerine: Django

- [Django ๊ฐ€์ƒํ™˜๊ฒฝ ์„ค์ •๊ณผ ์ฃผ์š” ๋ช…๋ น์–ด](/django/django-commands.md)
- [Django ํ‘œ์ค€ CRUD์™€ RESTful API](/django/django-crud-rest.md)
- [Django ORM](/django/django-orm.md)

- :thought_balloon: etc.
- [[Node.js] Unhandled 'error' event ์—๋Ÿฌ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•](/etc/node-listen-error.md)
- [[SQLite] ๋ฌธ๋ฒ•](/etc/sqlite-syntax.md)
Expand Down
78 changes: 78 additions & 0 deletions docs/django/django-commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
2019๋…„ 2์›” 14์ผ ๋ชฉ์š”์ผ

# Django ๊ฐ€์ƒํ™˜๊ฒฝ ์„ค์ •๊ณผ ์ฃผ์š” ๋ช…๋ น์–ด

## pyenv, virtualenv ์„ค์น˜

```bash
> git clone https://github.com/pyenv/pyenv.git ~/.pyenv
> echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
> echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
> echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
> exec "$SHELL"
> git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
> echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
> exec "$SHELL"
```

## ๊ฐ€์ƒํ™˜๊ฒฝ ์ƒ์„ฑ ๋ฐ ์„ค์ •

```bash
> mkdir TEST
> cd TEST
> pyenv virtualenv 3.6.7 <VENV_NAME>
> pyenv local <VENV_NAME>
> pip install django
```

## Project ์ƒ์„ฑ

```bash
> django-admin startproject <PROJECT_NAME> .
```

## App ์ƒ์„ฑ

```bash
> python manage.py startapp <APP_NAME>
```

## Server ์‹คํ–‰

```bash
> python manage.py runserver $IP:$PORT
```

## Migrations

```bash
> python manage.py makemigrations # Table ์ƒ์„ฑ
> python manage.py sqlmigrate articles 0001 # SQL๋กœ ์–ด๋–ป๊ฒŒ ๋งŒ๋“œ๋Š”์ง€ ๋ณด์—ฌ์คŒ
> python manage.py migrate # DB์— ์ ์šฉ
```

## Shell ์‹คํ–‰

```bash
> python manage.py shell
```

```shell
# python console
> from articles.models import Article
> a = Article(title="์™€ ์—ฌ๊ธฐ์„œ๋„ ๊ธ€์ด ์จ์ง„๋‹ค!!", content="์žฅ๊ณ  ์งฑ์งฑ๋งจ")
> a.save()
> Article.objects.all()
<QuerySet [<Article: Article object (1)>, <Article: Article object (2)>]>
> Article.objects.first()
<Article: ์ œ๋ชฉ: happy, ๋‚ด์šฉ: hacking>
```

> - Flask : Article.query.all()
> - Django : Article.objects.all()
## Admin ์„ค์ •

```bash
> python manage.py createsuperuser
```
26 changes: 26 additions & 0 deletions docs/django/django-crud-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
2019๋…„ 2์›” 20์ผ ์ˆ˜์š”์ผ

# Django ํ‘œ์ค€ CRUD์™€ RESTful API

## RESTful API

- **REST** : **Re**presentational **S**tate **T**ransfer

## 1. Read

- `articles/` : ๋ฆฌ์ŠคํŠธ ํŽ˜์ด์ง€
- `articles/1` : ๋””ํ…Œ์ผ ํŽ˜์ด์ง€

## 2. Create

- `articles/new` : ๊ธ€ ์ž‘์„ฑ ํŽ˜์ด์ง€
- `articles/create` : ๊ธ€ ์ž‘์„ฑ DB ๋ฐ˜์˜

## 3. Update

- `articles/1/edit` : ๊ธ€ ์ˆ˜์ • ํŽ˜์ด์ง€
- `articles/1/update` : ๊ธ€ ์ˆ˜์ • DB ๋ฐ˜์˜

## 4. Delete

- `articles/1/delete` : ๊ธ€ ์‚ญ์ œ ํŽ˜์ด์ง€
168 changes: 168 additions & 0 deletions docs/django/django-orm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
2019๋…„ 2์›” 21์ผ ๋ชฉ์š”์ผ

# Django ORM

## `__repr__` ๊ณผ `__str__`์„ ์“ฐ๋Š” ์ด์œ 

## `def __repr__(self)`

```python
# models.py
def __repr__(self):
return f'์ œ๋ชฉ: {self.title}, ๋‚ด์šฉ: {self.content}'
```

```bash
# python console
> Article.objects.all()
<QuerySet [์ œ๋ชฉ: happy, ๋‚ด์šฉ: hacking, ์ œ๋ชฉ: ์™€ ์—ฌ๊ธฐ์„œ๋„ ๊ธ€์ด ์จ์ง„๋‹ค!!, ๋‚ด์šฉ: ์žฅ๊ณ  ์งฑ์งฑ๋งจ]
> Article.objects.first()
์ œ๋ชฉ: happy, ๋‚ด์šฉ: hacking
```

```bash
> for a in Article.objects.all():
> print(a)
Article object (1)
Article object (2)
```
```bash
> for a in Article.objects.all()
> a
์ œ๋ชฉ: happy, ๋‚ด์šฉ: hacking
์ œ๋ชฉ: ์™€ ์—ฌ๊ธฐ์„œ๋„ ๊ธ€์ด ์จ์ง„๋‹ค!!, ๋‚ด์šฉ: ์žฅ๊ณ  ์งฑ์งฑ๋งจ
```
## `def __str__(self)`
```python
# models.py
def __str__(self):
return f'์ œ๋ชฉ: {self.title}, ๋‚ด์šฉ: {self.content}'
```
```bash
# python console
> for a in Article.objects.all():
> print(a)
์ œ๋ชฉ: happy, ๋‚ด์šฉ: hacking
์ œ๋ชฉ: ์™€ ์—ฌ๊ธฐ์„œ๋„ ๊ธ€์ด ์จ์ง„๋‹ค!!, ๋‚ด์šฉ: ์žฅ๊ณ  ์งฑ์งฑ๋งจ
```
# ORM Query ์กฐ์ž‘
## 1. Create
```bash
# python console
# method 1
> a = Article(title="happy", content="hacking")
> a.save()
```
```bash
# method 2
> Article.objects.create(title="hey!", content="create")
```
## 2. Read
### Select
```bash
# python console
> Article.objects.filter(title="happy").all()
> Article.objects.filter(title="happy").first()
```
> - Flask : Article.query.filter_by(title="happy").all()
>
> - Django : Article.objects.filter(title="happy").all()
### Select By
```bash
# python console
> Article.objects.get(pk=1) # primary key
> Article.objects.get(id=1) # column : id
> Article.objects.get(title="happy") # column : title
> Article.objects.filter(title="happy").first() # get(title="happy")์™€ ๋™์ผ
```
### Count
```bash
# python console
> Article.objects.filter(content="hacking").count()
> len(Article.objects.all())
2
> Article.objects.all().count()
2
```
### order_by
```python
# python console
> Article.objects.order_by('id').all() # ์˜ค๋ฆ„์ฐจ์ˆœ
> Article.objects.order_by('-id').all() # ๋‚ด๋ฆผ์ฐจ์ˆœ
```
## 3. Update
```bash
# python console
> a = Article.objects.get(id=1)
> a.content = "Thursday"
> a.save()
> Article.objects.get(id=1)
์ œ๋ชฉ: happy, ๋‚ด์šฉ: Thursday
```
## 4. Delete
```bash
# python console
> a = Article.objects.get(id=2)
> a.delete()
```
# Django CRUD
## ํŒจํ‚ค์ง€ ์„ค์น˜
```bash
> pip install django ipython django_extensions
```
## DB ์‹คํ–‰
```bash
> sqlite3 db.sqlite3 # sqlite3์œผ๋กœ ์‹คํ–‰
> python manage.py dbshell # DB shell ์ž๋™ ์‹คํ–‰(sqlite3)
```
```
> python manage.py shell
```
`ipython`, `django_extensions` ํŒจํ‚ค์ง€ ๋•๋ถ„์— ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ๊ณผ ๊ฐ™์€ ํ™˜๊ฒฝ์—์„œ ํŒŒ์ด์ฌ ์ฝ˜์†”์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
```bash
> python manage.py shell_plus
```
์žฅ๊ณ ์— ๋“ค์–ด๊ฐ„ ๋ชจ๋“  ํ™˜๊ฒฝ์„ autoload ํ•ด์ค€๋‹ค. `from articles.models import Article` ๊ณผ ๊ฐ™์€ ์ž‘์—…์„ ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
# Django ORM Relationships
```bash
> Comment.objects.filter(article_id=1).all
> Article.objects.first().comment_set.all()
```
```bash
> Comment.objects.first().article
> Article.objects.all().get(pk=Comment.objects.first().article_id)
```
28 changes: 28 additions & 0 deletions docs/etc/react-apollo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
2019๋…„ 5์›” 1์ผ ์ˆ˜์š”์ผ

# React Apollo

## GraphQL?

GraphQL์€ ์„œ๋ฒ„ API๋ฅผ ํ†ตํ•ด ์ •๋ณด๋ฅผ ์ฃผ๊ณ ๋ฐ›๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ์ฟผ๋ฆฌ์–ด๋‹ค. GraphQL API๋Š” ๋ณดํ†ต ํ•˜๋‚˜์˜ ์—”๋“œํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, ์š”์ฒญ์‹œ ์‚ฌ์šฉํ•˜๋Š” ์ฟผ๋ฆฌ๋ฌธ์— ๋”ฐ๋ผ ์‘๋‹ต์˜ ๊ตฌ์กฐ๊ฐ€ ๋‹ฌ๋ผ์ง„๋‹ค.

## Apollo Client?

Apollo Client๋Š” ํด๋ผ์ด์–ธํŠธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ GraphQL๊ณผ์˜ ๋ฐ์ดํ„ฐ ๊ตํ™˜์„ ๋„์šฐ๋ฉฐ, ํŠน๋ณ„ํžˆ ๋ฆฌ์•กํŠธ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ React Apollo๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

์ž‘์„ฑ๋œ GraphQL ์ฟผ๋ฆฌ๋Š” Apollo Client์—์„œ ์ปดํฌ๋„ŒํŠธ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

* Query - Retrieve Data ("GET")
* Mutation - Manipulate Data ("POST", "PUT", "PATCH", "DELETE")
* SUbscription - Set up realtime connection via Websockets

### Query

๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ฌ ๋• Query ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ์ด ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” GraphQL ์ฟผ๋ฆฌ๋ฅผ props๋กœ ๋„ฃ์–ด์ค˜์•ผ ํ•œ๋‹ค.

Query ์ปดํฌ๋„ŒํŠธ์— ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ loading, error์™€ ํ•จ๊ป˜ Query ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์ œ๊ณตํ•˜๋Š” data๋ฅผ ๋„˜๊ฒจ์ค€๋‹ค. Query ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋งˆ์šดํŠธ๋˜๋ฉด, ์•„ํด๋กœ ํด๋ผ์ด์–ธํŠธ๋Š” ์ฟผ๋ฆฌ์—๋Œ€ํ•œ observer๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ์ปดํฌ๋„ŒํŠธ๋Š” ์•„ํด๋กœ ํด๋ผ์ด์–ธํŠธ ์บ์‹œ๋ฅผ ํ†ตํ•ด ์ฟผ๋ฆฌ์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ๊ฐ’์„ ๊ตฌ๋…ํ•œ๋‹ค. ๋จผ์ €, ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ๊ฐ’์„ ์•„ํด๋กœ ์บ์‹œ๋กœ๋ถ€ํ„ฐ ๊ฐ€์ ธ์˜จ๋‹ค. ์—†์„ ๊ฒฝ์šฐ, ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉฐ, ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์œผ๋ฉด ์•„ํด๋กœ ์บ์‹œ์— ์ €์žฅ์„ ํ•œ๋‹ค.




์ถœ์ฒ˜ : https://medium.com/@shlee1353/%EB%A6%AC%EC%95%A1%ED%8A%B8-%EC%95%84%ED%8F%B4%EB%A1%9C-react-apollo-%EB%A6%AC%EB%8D%95%EC%8A%A4%EC%99%80-%EB%AC%B4%EC%97%87%EC%9D%B4-%EB%8B%A4%EB%A5%B8%EA%B0%80-a4bfdb48bbc
Loading

0 comments on commit e0f36a0

Please sign in to comment.