Skip to content

Instantly share code, notes, and snippets.

@xodhx4
xodhx4 / Markdium-javascript.js
Created April 2, 2020 11:29
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
async function alertResult() {
callApi() // Promise를 이용한 Non Blocking IO 처리
.then(result => {
console.log(result)
})
}
@xodhx4
xodhx4 / Markdium-javascript.js
Created April 2, 2020 11:29
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
function returnDataAfter2Seconds() { // 2초 뒤에 값을 돌려주는 IO 작업
return new Promise(resolve => { // 2초 동안 Blocking 되지 않기 위해 Promise 객체를 return 한다
setTimeout(() => {
resolve('data');
}, 2000);
});
}
f = returnDataAfter2Seconds();
// const data = f.result(); Blocking IO이기 때문에 js에는 존재하지 않는다
@xodhx4
xodhx4 / Markdium-python.py
Created April 2, 2020 11:29
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
future = excutor.submit(open, "example.txt", "r") // Non-Blocking IO로 IO 작업 시작
some_cpu_job1() // cpu 작업이 IO작업이 끝나기 전에 끝난다
f = future.result() // 결과값을 가져올 떄까지 쓰레드가 Blocking된다 -> 비효율적
print(f.readline())
some_cpu_job2()
some_cpu_job3()
@xodhx4
xodhx4 / Markdium-python.py
Created April 2, 2020 11:29
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
f = open('example.txt', 'r') // example.txt를 읽어서 파일 객체 f를 리턴해준다
print(f.readline()) // 한 줄을 읽어서 화면에 출력한다
@xodhx4
xodhx4 / Markdium-javascript.js
Created April 2, 2020 11:29
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
async function returnPromiseResolveOne() {
return 1;
}
returnPromiseResolveOne().then(alert);
@xodhx4
xodhx4 / Markdium-javascript.js
Created April 2, 2020 11:29
Markdium-JS 초보가 쓰는 async await 처음부터 이해하기
function resolveAfter3Seconds() { // 3초 동안 대기하게 함
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved1');
}, 3000);
});
}
function resolveAfter2Seconds() { // 2초 동안 대기하게 함
return new Promise(resolve => {
@xodhx4
xodhx4 / ArrayAndListSort.java
Created February 29, 2020 13:26
[자바 정렬하기] 자바에서 배열, 리스트를 정렬하는 방법 #sort
class SortEx {
public void main() {
int[] intArr = new int[3] {1, 2, 3};
# 배열 오름차순 정렬
Arrays.sort(intArr);
# 배열 내림차순 정렬
Arrays.sort(intArr, Comparator.reverseOrder());
# 리스트 정렬
List<String> strList = Arrays.asList("1", "2", "3");
@xodhx4
xodhx4 / hjkl.ahk
Created February 27, 2020 14:46
[Autohotkey 스크립트]
!h:: SendInput,{LEFT}
!j:: SendInput,{DOWN}
!k:: SendInput,{UP}
!l:: SendInput,{RIGHT}
LCtrl::Capslock
Capslock::LCtrl
; Tab을 한 번 누르면 esc 후 무조건 영어로
; Tab이 더블클릭되면 원래처럼 Tab
; https://autohotkey.com/board/topic/96752-need-help-with-a-double-tap-function/
@xodhx4
xodhx4 / git.sh
Created February 20, 2020 04:51
[git 자주쓰는 명령어] git에서 자주 사용하지만 헷갈리는 명령어 #git #cheatsheet
# git lg 로 git 명령어 alias
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# staing과 work directory의 차이
git diff
# HEAD와 Stage의 차이
git diff --cached
# HEAD와 work directory의 차이
@xodhx4
xodhx4 / stringFormat.java
Created February 18, 2020 13:50
[Fotmatted String] 스트링을 포맷팅해서 사용하는 법 #String #format
public static void stringFormat() {
for (int i=0; i<10; i++) {
String.format("%d%d", i, i);
}
}