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 / rainbow.js
Last active February 23, 2023 10:38
Give dynamic rainbow colored borders to ALL the elements being found in query. Quite useful for testing CSS
// Give dynamic rainbow colored borders to ALL the elements being found in query. Quite useful for testing CSS
function rainbow(query, styles) {
var colors = ['Red', 'Lime', 'Blue', 'Yellow', 'Cyan', 'Magenta', 'Silver', 'Gray', 'Maroon', 'Olive', 'Green', 'Purple', 'Teal', 'Navy']
document.querySelectorAll(query).forEach(function(el) {
var rand = Math.floor(Math.random() * colors.length);
var color = colors[rand];
el.style.border = '2px ridge ' + color;
if(styles != undefined) {
for(var [key, val] of Object.entries(styles)) {
el.style[key] = val;
@daanta-real
daanta-real / CustomAppender.java
Last active December 28, 2022 00:31
Logback custom appender - minimal example
package utils.logging;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import org.slf4j.LoggerFactory;
public class CustomAppender extends AppenderBase<ILoggingEvent> {
@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.