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 / random password.js
Created April 27, 2024 13:49
random password generator
function generateRandomPassword(length) {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_+=[]{}|;:,.<>? ";
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
return password;
}
var a1;
var a2 = [];
var a3 = {};
var a4 = {x:undefined};
var a5 = {x:'1'};
console.log("a1:", a1?.x || 'error');
console.log("a2:", a2?.x || 'error');
console.log("a3:", a3?.x || 'error');
console.log("a4:", a4?.x || 'error');
@daanta-real
daanta-real / dbColsToVOVarNames.js
Last active April 11, 2023 03:15
Convert DB column name to camelCase for using their names in VO
function toCamelCase(str){
var regExp=/[-_]\w/ig;
return str.toLowerCase().replace(regExp,function(match){
return match.charAt(1).toUpperCase();
});
}
function toCamelCaseList(arr) {
let result = [];
arr = arr.split("\n");
for(var a of arr) {
@daanta-real
daanta-real / DebugPopup.html
Last active April 4, 2023 01:16
Debug informimg popup boilerplate
<Style type="text/css">
pre { display:none; background:red; color:white; font-weight:bold; padding:5px; width:850px; }
</Style>
<pre id="debugPre" style="display:none;">
Your debugging HTML HERE
</pre>
<script type="text/javascript">
@daanta-real
daanta-real / PrintFormData.js
Last active March 6, 2023 02:28
Read and print all form data to console
function printFormData(formId) {
const formEl = document.getElementById(formId);
const formData = new FormData(formEl);
const params = {};
for(const [key, val] of formData.entries()) {
params[key] = val;
}
@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"