Skip to content

Instantly share code, notes, and snippets.

@bepyan
bepyan / BinaryArrayTree.java
Last active May 26, 2021 11:19
BinaryArrayTree Traversal
import java.io.*;
import java.util.*;
public class BinaryArrayTree {
private List<Integer> list = new ArrayList<>();
public BinaryArrayTree(int n) {
list.add(null);
for (int i = 1; i <= n; i++)
@bepyan
bepyan / $.java
Created May 26, 2021 11:08
Sort Testing
import java.util.Arrays;
public class $ {
public static <T extends Comparable<T>> int compare(T a, T b) {
return a.compareTo(b);
}
public static <T extends Comparable<T>> void swap(T[] a, int i, int j) {
T tmp = a[i];
@bepyan
bepyan / PQ.js
Created August 19, 2021 09:17
알고리즘 문제 풀이용 우선순위 큐
/**
* @arr 초기 배열
* @compare 객체에 대한 비교 함수
*/
const PQ = (arr, compare = (a, b) => a > b) => {
const heap = [];
const getPIdx = (i) => Math.floor((i - 1) / 2);
const getLIdx = (i) => i * 2 + 1;
const getRIdx = (i) => i * 2 + 2;
@bepyan
bepyan / crawler.js
Last active December 15, 2021 11:06
생명의 삶 QT 본문 크롤러 입니다.
import axios from "axios"
import cheerio from "cheerio"
import iconv from "iconv-lite";
const getDate = () => {
const date = new Date().toISOString().substring(0, 10)
const KO_DAY = ['일', '월', '화', '수', '목', '금', '토'];
return `${date} (${KO_DAY[new Date().getDay()]})`
}
🌞 Morning 75 commits █▍░░░░░░░░░░░░░░░░░░░ 6.7%
🌆 Daytime 209 commits ███▉░░░░░░░░░░░░░░░░░ 18.7%
🌃 Evening 454 commits ████████▌░░░░░░░░░░░░ 40.7%
🌙 Night 377 commits ███████░░░░░░░░░░░░░░ 33.8%
@bepyan
bepyan / Store.js
Created June 7, 2022 04:48
vanillaJS core util - global state
export default class Store {
#state = {};
#listeners = [];
#reducer;
/**
* 액션을 수행하고 새로운 state를 반환한다. dispatch를 통해 원하는 액션을 수행할 수 있다.
* @param {{}} state
* @param {{ payload: {} }} reducer
const reducer = (state, actionKey, { payload = {} }) => {