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 / 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); }
@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 / 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