Skip to content

Instantly share code, notes, and snippets.

View daanta-real's full-sized avatar
🔥

Junsung Park / Daanta daanta-real

🔥
View GitHub Profile
@daanta-real
daanta-real / highlight_kh.html
Last active October 7, 2021 00:46
highlight.js 커스터마이징
<!--
개요:
- KH 과제게시판에 코드를 올리기 위해 커스터마이징한 highlight.js 응용 코드.
특징:
- Consolas 폰트 사용
- 모바일 레이아웃 지원 (margin/padding 없는 꽉찬 레이아웃 뷰, 가로스크롤, 줄번호 등)
- 눈에 더 편하게 보일 수 있도록 일부 엘리먼트 색상 조정
사용법:
@daanta-real
daanta-real / getFileSizeFormatedTxt.java
Last active September 15, 2021 16:53
Get the formatted text of a file size
// What you input: file size (long or its sub type)
// What you get: formatted text of a file size.
// ex) 23.44 MBytes, 15.20 TBytes, 1,015 Bytes, ...
public static String getFileSizeFormatedTxt(long fileSize) {
// Unit size infoes
Object[][] bytes = {
{1099511627776L, "T"},
{1073741824L , "G"},
{1048576L , "M"},
@daanta-real
daanta-real / ArrayReverse.java
Created August 25, 2021 01:24
Reverse a single dimension array's elements (all types)
public static Object array_reverse(Object[] arr) {
for(int i = 0; i < arr.length / 2; i++) {
int start = i;
int end = arr.length - 1 - i;
Object temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
}
return arr;
@daanta-real
daanta-real / ArrayCirculator.java
Created August 25, 2021 00:47
Array Circulator : circulate an single dimension array with the times and the direction what you want
public class c01_ArrayShifter {
// Circulate the number in case of overflow
private static int chk_overflow(int num, int len) {
return num >= len ? (num - len)
: num < 0 ? (num + len)
: num;
}
// Circulate an array with the times and the direction what you want
@daanta-real
daanta-real / array_reverse_int.java
Created August 21, 2021 12:12
Array reverse - for int type
// A method of returning an array which has reversed order of the original int[] array
public static int[] array_reverse_int(int[] arr1) {
int[] arr2 = new int[arr1.length];
for(int i = 0; i < arr1.length; i++) arr2[i] = arr1[arr1.length - 1 - i];
return arr2;
}
// Let's run a sample code
public static void main(String[] args) {
@daanta-real
daanta-real / monthNum_to_SeasonNum.java
Last active August 19, 2021 08:19
How to get the season number (0 ~ 3) from a month number (1 ~ 12) - only for the north hemisphere
// What you need to input: a month number (1~12)
// What you will get: 0 is winter, 1 is spring, 2 is summer, 3 is autumn
private static String getSeasonName(int m) { return new String[]{ "Winter", "Spring", "Summer", "Autumn" }[m / 3 % 4]; }
// Let's convert each month number to the season string
for(int m = 1; m <= 12; m++) System.out.printf("%2d → %s", i, getSeasonName(m) + "\n");
/*
[[result]]
1 → Winter
@daanta-real
daanta-real / chkIfMinutesPassed.java
Last active August 16, 2021 09:41
0분이면 false를, 1 ~ 59분이면 true를 리턴하는 정수
// 입력된 분(currM)이 0이면 0, 1 ~ 59분이면 1을 갖게 되는 정수이다.
// 1시간단위 선불 PC방에서 1분 이상 이용 시 1시간 요금을 추가로 더할 때 등에 사용한다.
// 딱 분단위만 따진다. 초단위로 계산하지는 않으니 다른것을 쓰라.
int plusHour_becauseofMinutes = (1 - ((60 - currM) / 60));