Skip to content

Instantly share code, notes, and snippets.

View qb20nh's full-sized avatar
💭
I may be slow to respond.

Yoo Taejong qb20nh

💭
I may be slow to respond.
  • 21:00 (UTC +09:00)
View GitHub Profile
@qb20nh
qb20nh / search-anywhere.user.js
Created December 6, 2019 04:57
Search Anywhere
// ==UserScript==
// @name Search Anywhere
// @namespace http://tampermonkey.net/
// @version INITIAL
// @description Press Alt+D to activate search function within a webpage, Press Alt+D,D(Double Tap) for default browser behavior.
// @author tez
// @include http://*/*
// @include https://*/*
// @grant none
// ==/UserScript==
@qb20nh
qb20nh / app.js
Created September 27, 2021 14:50
FizzBuzz
const testFizzBuzz = (fizzbuzz) => {
const assert = (value) => {
if (value === true) {
return;
} else {
throw 'Assertion failed';
}
};
const input = [ ...Array(15).keys() ].map(e=>e+1);
@qb20nh
qb20nh / ValueExample.java
Created October 20, 2021 11:03
Automatically fix hangul encoding
import java.io.UnsupportedEncodingException;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ValueExample {
@qb20nh
qb20nh / Pagination.java
Created December 6, 2021 13:44
Java Pagination Example
package kr.co.benew.util;
import java.util.List;
import org.apache.ibatis.session.RowBounds;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Pagination<T> {
@qb20nh
qb20nh / rps.js
Created December 7, 2021 13:19
RPS.js
let com = Math.random()*3 | 0
let usr
const rps = 'rock paper scissors'.split(' ')
const score = 'draw win lose'.split(' ')
let usrNum
while ((usrNum = rps.indexOf(usr = prompt('choose your move'))) === -1) {
alert('invalid move')
@qb20nh
qb20nh / intercept-function.js
Last active December 11, 2021 12:39 — forked from tilmanschweitzer/intercept-function.js
Function to intercept functions calls even to nativ functions.
const interceptFunction = (object, fnName, options) => {
const noop = () => {}
const fnToWrap = object[fnName]
const before = options.before || noop
const after = options.after || noop
object[fnName] = function (...args) {
before.apply(this, args)
const result = fnToWrap.apply(this, args)
after.apply(this, args, result)
@qb20nh
qb20nh / template.js
Last active December 17, 2021 06:38
Populate jstl-el-like expressions with JS
const iterateNode = (rootNode, [attrVisitor, textVisitor]) => {
if (rootNode instanceof Node) {
for(const node of rootNode.childNodes) {
if (node instanceof Element) {
for (const attr of node.attributes) {
attrVisitor.call(null, attr)
}
iterateNode(node, [attrVisitor, textVisitor])
} else if (node instanceof Text) {
textVisitor.call(null, node)
@qb20nh
qb20nh / json_format.js
Last active December 17, 2021 06:35
Simple json formatter
const json_format = (jsons, level = 2) => {
let i = 0
return JSON.stringify(JSON.parse(jsons)).replace(/\[\]|\{\}|[{[,\]}]/g,
c => ['[]', '{}'].includes(c) ? c : '{[,'.includes(c) ? c + '\n' + (','.includes(c) ? ' '.repeat(i * level) : ' '.repeat(++i * level)) : '\n' + ' '.repeat(--i * level) + c)
.replace(/"(?:[^"]|\\")+"(:)/g, '$& ')
}
@qb20nh
qb20nh / HttpRedirectionInterceptor.java
Last active January 14, 2022 09:29
Intercept Redirect
package kr.co.benew.iddle_admin.servlet;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.UnaryOperator;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
from time import sleep, time
import os
def binary_search(condition, low, high):
if callable(condition) and high > low:
mid = int((high + low) / 2)
res = condition(mid)