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 / hidingtoast.html
Last active November 24, 2022 05:34
A toast appears and immediately fadeout, and finally removed
<style>
@keyframes fadeout {
from { opacity:1; }
to { opacity:0; }
}
.toast {
position:fixed; left:0; bottom:0; padding:10px;
font-size:50px; color:red; font-weight:900;
animation: fadeout 1s ease-in forwards;
@daanta-real
daanta-real / jsonBeautifier.js
Last active November 17, 2022 05:36
Beautify JSON
// if you put isHTML parameter true you'll get newline char as br HTML tag, or just get "\n"
function jsonBeautifier(jsonTxt, isHTML) {
let result = JSON.stringify(JSON.parse(jsonTxt), null, 4);
if(isHTML) result = result.replaceAll("\n", "<br />");
return result;
}
@daanta-real
daanta-real / getPaddedStr.js
Created October 28, 2022 06:09
Get Padded String
// String ์ฑ„์šฐ๊ธฐ(padding)
// ์‚ฌ์šฉ๋ฒ•: getPaddedStr(์›๋ณธ๋ฌธ์ž์—ด, ํŒจ๋”ฉ์ด ํฌํ•จ๋œ ์ด ๊ธธ์ด, ์ฑ„์šธ ๋ฌธ์ž์—ด, ์ฑ„์šธ ๋ฐฉํ–ฅ)
// ex) getPaddedStr("1135j", 10, "#", "left") = "#####1135j"
function getPaddedStr(strOrg, width, to, direction) {
if(!strOrg) return "";
var strOrg = new String(strOrg), len = strOrg.length;
if(len >= width) return strOrg;
var strPad = new Array(width - len + 1).join(to);
return (direction == "left"
@daanta-real
daanta-real / getPagingProps.js
Last active October 28, 2022 06:53
Get all paging props in once
// ํ•„์š” ์ •๋ณด๋ฅผ ๋‹ด์€ ๊ฐ์ฒด๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ํŽ˜์ด์ง• ์ •๋ณด๋ฅผ ์ถ”๊ฐ€ํ•ด์„œ ๋ฐ˜ํ™˜ํ•ด ์ฃผ๋Š” ํ•จ์ˆ˜
// ํ•„์š” ์ •๋ณด: ๊ฐ์ฒด. currPage(ํ˜„์žฌํŽ˜์ด์ง€), totalArticles(์ „์ฒด ๊ธ€ ์ˆ˜), rowsPerPage(1ํŽ˜์ด์ง€ ๋‹น ๊ธ€ ์ˆ˜), pagesPerView(1๋ทฐ ๋‹น ํŽ˜์ด์ง€ ์ˆ˜)
// IE 11 CAPABLE
function getPagingProps(p) {
// Chksum
if(typeof p === "undefined") throw new Error("'p' object required");
if(typeof p != "object") throw new Error("'p' must be an object");
["currPage", "totalArticles", "rowsPerPage", "pagesPerView"].forEach(function(i) {
if(!p.hasOwnProperty(i) || isNaN(parseFloat(p[i]))) throw new Error("'" + i + "' has an error");
@daanta-real
daanta-real / getDateByString.js
Last active July 4, 2022 06:00
Get new Date class by one string (Cross-browsing available)
function getDateByString(dateStr) {
// String ๋ฏธ์ž…๋ ฅ ์‹œ return
if(dateStr == undefined || !dateStr || typeof dateStr != "string" || dateStr.length < 10) return;
console.log(dateStr);
// YMD
var year = parseInt(dateStr.substring(0, 4));
@daanta-real
daanta-real / file_getDebugYN.java
Created June 29, 2022 15:50
Open a file and read inner T/F value
import java.io.File;
import java.util.Scanner;
public class Debug {
// ๋””๋ฒ„๊ทธ์šฉ ๋กœ๊ทธ์ธ์—ฌ๋ถ€ ์ง€์‹œ ํŒŒ์ผ ๋‚ด์šฉ์ด true์ธ์ง€ ์•„๋‹Œ์ง€,
// ์ฆ‰ ๊ฐ•์ œ ๋กœ๊ทธ์ธ์„ ์ง€์‹œํ–ˆ๋Š”์ง€ ์•„๋‹Œ์ง€๋ฅผ ์•Œ์•„๋‚ด์–ด ํšŒ์‹ 
// Open a file which indicates about the debug mode,
// get the debug mode is true or not, and return it
public static boolean getDebug() {
@daanta-real
daanta-real / downloadExecute.js
Created June 23, 2022 06:23
File download function for modern browsers ( = excluding IE)
function downloadExecute(downloadURL) {
fetch(downloadURL)
.then(function(response) {
return response.blob();
}).then(function(blob) {
var fileBlob = new Blob([blob], {type: blob.type});
var aLink = document.createElement("a");
aLink.href = window.URL.createObjectURL(fileBlob);
aLink.download = decodeEntity(pageData.fileName);
<!--
I made this to use spinner with the simplest way and with reduced code.
Usage โ†’ Simple
โ‘  CSS code โ†’ Edit the size/color in :root{} and paste all to ur page.
โ‘ก HTML โ†’ Just type <div class="spinner"></div> at the location u want.
โ‘ข Want to turn on the spinner? just add ".loading" class to the spinner element.
Want to turn off? remove ".loading" class.
Done. That's all.
@daanta-real
daanta-real / showFormStr.js
Last active October 20, 2021 09:49
Get all names and values of one form
// Get the names & values of one specific form by the name in the page
// limitations: can be used only for simple form (no relation with other tags)
// ํŠน์ • ์ด๋ฆ„์˜ form ๋‚ด์—ญ ์ถœ๋ ฅ
function showFormStr(name) {
var str = "";
document.forms[name].childNodes.forEach((el) => {
if(el.name !== undefined && el.name.length > 0) str += el.name + " = " + el.value + "\n";
});
console.log(str);
}
@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); }