gist 여러 파일 중 하나만 포스트 하기
gist를 사용하다 보면 한 gist에 여러 file을 올리는 경우가 생깁니다.
이때, 글로 포스팅 하려고 할 때 script코드를 그대로 가져다 쓰면 모든 파일의 코드 블록이 생깁니다.
여기서 자기가 원하는 file만 코드 블록을 만들고 싶으면 아래 내용을 참조 바랍니다.
gist 여러 개 파일
소스 코드 올릴 때 gist 활용 글을 이용해서 gist를 올릴 때 아래 사진 처럼 한 gist에 여러 file을 올리는 경우가 생긴다.
이때, gist의 Embed코드를 그대로 사용하면 아래와 같이 2개의 코드 블록이 생기는 것을 확인 할 수 있다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 11723번: 집합 | |
import sys | |
input=sys.stdin.readline | |
def func(cmd,S): | |
val=int(cmd[1]) | |
if cmd[0] == 'add': | |
S.add(val) | |
elif cmd[0] == 'remove': | |
S.discard(val) | |
elif cmd[0] == 'check': | |
print(1 if val in S else 0) | |
elif cmd[0] == 'toggle': | |
if val in S: | |
S.discard(val) | |
else: | |
S.add(val) | |
S=set() | |
M=int(input()) | |
for _ in range(M): | |
cmd=input().strip().split() | |
if cmd[0] == 'all': | |
S = set(range(1,21)) | |
elif cmd[0] == 'empty': | |
S = set() | |
else: | |
func(cmd,S) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 11723번: 집합 | |
# bit로 집합 나타내기 | |
import sys | |
input=sys.stdin.readline | |
S,all=0,(1<<20) - 1 | |
M=int(input()) | |
for _ in range(M): | |
cmd=input().strip().split() | |
if cmd[0] == 'all': | |
S = all | |
elif cmd[0] == 'empty': | |
S = 0 | |
else: | |
val= 1<<int(cmd[1]) - 1 | |
if cmd[0] == 'check': | |
print(1 if S & val else 0) | |
elif (cmd[0] == 'add' and S & val == 0) or (cmd[0] == 'remove' and S & val) or (cmd[0] == 'toggle'): | |
S ^=val |
gist의 여러 파일 중 원하는 파일만 코드 블록 만들기
여기서 자신이 원하는 파일만 코드 블록을 만들고 싶으면 먼저 위 사진에서 gist의 자신이 원하는 파일명(그림에서 빨간 사각형)을 script 의 src
속성에서 뒤에 추가적으로 query문으로 사용하여 해결 할 수 있다. API을 사용하여 해결할 수도 있지만 이렇게 하면 굳이 API까지 사용하는 번거로움을 없앨 수 있다.
<script src="https://gist.github.com/N-analyst/0fa193a4514e104dbb8133e063b36113.js?file=baekjoon_11723_2nd.py"></script>
원래 ~.js까지 기본 코드일 것이다. 여기서 그 뒤에?file=(원하는 파일 명)을 적어주면 선택한 파일만 코드 블록이 생긴다. 여기서 필자는 두 개의 파일 중 baekjoon_11723_2nd.py
파일 선택.
📌 결과
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 11723번: 집합 | |
# bit로 집합 나타내기 | |
import sys | |
input=sys.stdin.readline | |
S,all=0,(1<<20) - 1 | |
M=int(input()) | |
for _ in range(M): | |
cmd=input().strip().split() | |
if cmd[0] == 'all': | |
S = all | |
elif cmd[0] == 'empty': | |
S = 0 | |
else: | |
val= 1<<int(cmd[1]) - 1 | |
if cmd[0] == 'check': | |
print(1 if S & val else 0) | |
elif (cmd[0] == 'add' and S & val == 0) or (cmd[0] == 'remove' and S & val) or (cmd[0] == 'toggle'): | |
S ^=val |
여기 코드는 예시로 사용하기 위해서 백준의 11723번: 집합 문제의 2개의 풀이를 올리고 사용하였습니다.
'마크다운(Typora) > 사용법' 카테고리의 다른 글
티스토리, 마크 다운 글꼴 바꾸기 (0) | 2021.08.22 |
---|---|
티스토리 코드블럭, gist 줄 없애기 (0) | 2021.08.20 |
소스 코드 올릴 때 Github gist 활용하기 (0) | 2021.08.20 |
마크 다운 작은 Code에만 글자색 바꾸기 (0) | 2021.02.12 |
티스토리에 쥬피터 노트북 올리기 (0) | 2020.11.25 |
알고리즘 소스 코드 올리기 (0) | 2020.10.18 |
Typora에서 글자색 바꾸기 (3) | 2020.10.18 |
Typora로 작업한 마크다운 포스팅 방법 (0) | 2020.10.16 |