Skip to content

Instantly share code, notes, and snippets.

View silverprize's full-sized avatar
🤟

SilverPrize silverprize

🤟
  • Seoul, South Korea
View GitHub Profile
@silverprize
silverprize / Base64.groovy
Last active August 29, 2015 14:10
base64 encoding
intToBase64 = [
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'
]
def encode(InputStream is) {
int countByte = 2
@silverprize
silverprize / MergeSort.scala
Created December 5, 2014 09:04
Mergesort with scala
object MergeSort {
def sort(source: Array[Int]): Unit = {
branch(source, 0, source.length)
}
private def sortAndMerge(source: Array[Int],
offset0: Int, len0: Int,
offset1: Int, len1: Int): Unit = {
val buffer = new Array[Int](len0 + len1)
@silverprize
silverprize / HeapSort.scala
Created December 9, 2014 15:27
Heapsort with scala
object HeapSort {
def sort(source: Array[Int]): Unit = {
buildHeap(source)
lineUp(source)
}
private def buildHeap(source: Array[Int]): Unit = {
def moveUp(source: Array[Int], idx: Int): Unit = {
if (idx > 0) {
val pIdx = Math.round(idx * 0.5f) - 1
@silverprize
silverprize / heapsort.clj
Last active August 29, 2015 14:11
Heapsort with clojure
(defn- round [idx]
(int (+ idx 0.5)))
(defn- get-parent-idx [idx]
(dec (round (* idx 0.5))))
(defn- get-left-child-idx [idx]
(inc (* idx 2)))
(defn- get-right-child-idx [idx]
@silverprize
silverprize / quicksort.clj
Last active August 29, 2015 14:11
Quicksort with clojure
(defn- swap [source idx0 idx1]
(def tmp (aget source idx0))
(aset source idx0 (aget source idx1))
(aset source idx1 tmp))
; find median among start/mid/end
(defn- get-pivot [source start len]
(let [end (+ start (dec len)) mid (+ start (int (/ len 2)))]
(if
(or
@silverprize
silverprize / count-the-coins.clj
Created January 2, 2015 09:43
Count the coins with clojure
(defn- count-change [coins offset target]
(if (= target 0)
1
(loop [coins coins offset offset target target sum 0]
(if (< offset (alength coins))
(if (>= target (nth coins offset))
(recur coins (inc offset) target (+ sum (count-change coins offset (- target (nth coins offset)))))
(recur coins (inc offset) target sum))
sum))))
@silverprize
silverprize / SecurityConfig.java
Last active July 25, 2017 06:21
spring security authentication configuration for content-type application/json
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@silverprize
silverprize / m4a2mp3.sh
Created March 1, 2020 15:10
m4a to mp3 with ffmpeg
# convert all m4a to mp3 in directory
# mp3 256k bitrate
for f in *.m4a; do name=`basename ${f} .m4a`; ffmpeg -i ${f} -acodec libmp3lame -ab 256k ${name}.mp3; done
@silverprize
silverprize / intellij-problems.md
Last active March 26, 2020 04:11
IntelijJ problems
@silverprize
silverprize / vue-problems.md
Last active July 16, 2020 07:25
vue-problems

Vue.js + TSX + Storybook 구성이 불가능함

Storybook 패키지로부터 react, react-dom, emotion 패키지의 타입 정의가 컴파일에 포함되는데,
vue에 맞게 intrinsic elements, value-based elements를 타입 호환이 되도록 맞출수가 없다. storybookjs/storybook#7379

템플릿 기반 functional component의 v-for & ref 오동작

부모 컴포넌트에서 functional component엘리먼트에 v-for와 ref를 적용했을때 refInFor가 적용되지 않음.
ref에 지정한 이름의 프로퍼티에 엘리먼트 array로 저장되지 않고 v-for의 마지막 엘리먼트만 저장됨. vuejs/vue#10171 찾아봤는데 vue-template-compiler에 결함이 있다.