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 / 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));
@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 / 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 / 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 / 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 / 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 / highlight_kh.html
Last active October 7, 2021 00:46
highlight.js ์ปค์Šคํ„ฐ๋งˆ์ด์ง•
<!--
๊ฐœ์š”:
- KH ๊ณผ์ œ๊ฒŒ์‹œํŒ์— ์ฝ”๋“œ๋ฅผ ์˜ฌ๋ฆฌ๊ธฐ ์œ„ํ•ด ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•œ highlight.js ์‘์šฉ ์ฝ”๋“œ.
ํŠน์ง•:
- Consolas ํฐํŠธ ์‚ฌ์šฉ
- ๋ชจ๋ฐ”์ผ ๋ ˆ์ด์•„์›ƒ ์ง€์› (margin/padding ์—†๋Š” ๊ฝ‰์ฐฌ ๋ ˆ์ด์•„์›ƒ ๋ทฐ, ๊ฐ€๋กœ์Šคํฌ๋กค, ์ค„๋ฒˆํ˜ธ ๋“ฑ)
- ๋ˆˆ์— ๋” ํŽธํ•˜๊ฒŒ ๋ณด์ผ ์ˆ˜ ์žˆ๋„๋ก ์ผ๋ถ€ ์—˜๋ฆฌ๋จผํŠธ ์ƒ‰์ƒ ์กฐ์ •
์‚ฌ์šฉ๋ฒ•:
@daanta-real
daanta-real / gist:d3ff7f525592b9d06e90972d14e1e414
Created October 5, 2021 22:50
Changes the string values to * the position after all of 'n'th characters
public class Main {
// Returns the string which changed all characters after 'n'th to *
public static String strToStar(String s, int n) {
return s.substring(0, n)
+ new String(new char[s.length() - n])
.replace("\0", "*");
}
// Test
@daanta-real
daanta-real / getTableStr.java
Last active October 17, 2021 03:29
Returns the single table map of String from 2-dimensions String array
// Returns the Table String from a String[][] data
public static String getTableStr (String[][] data) {
// Calculate the maximum lengths of the each columns
int[] len = new int[data[0].length];
Arrays.fill(len, 0);
for(String[] str: data) {
for(int i = 0; i < str.length; i++ ) {
String val = str[i];
int stringLen = val == null ? 0 : val.length();
if(stringLen > len[i]) len[i] = stringLen;
@daanta-real
daanta-real / 0๋ฒˆ์งธํŒŒ์ผ_$.java
Last active October 7, 2021 14:28
Test17 ~ Test18 ํ…Œ์ด๋ธ”ํ™•์žฅ๊ฒ€์ƒ‰๊ธฐ
์ฝ”๋“œ ๋‹จ์ถ• ๋ฐ ๊ธฐ๋Šฅ ํ™•์žฅ์„ ์œ„ํ•ด ๋งŒ๋“ค์–ด๋ณธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค.
1. $.pr / $.pn / $.pf : ์ฝ”๋“œ๋‹จ์ถ•์šฉ ๋ฉ”์†Œ๋“œ
// System.out.print โ†’ $.pr ์ฝ”๋“œ๋‹จ์ถ•
// System.out.println โ†’ $.pn ์ฝ”๋“œ๋‹จ์ถ•
// System.out.printf โ†’ $.pf ์ฝ”๋“œ๋‹จ์ถ•
public static void pr (Object o) { System.out.print(o); }