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 / emoji-unicode.md
Last active February 23, 2024 00:36
Emoji on Unicode

참고글 : https://blog.jonnew.com/posts/poo-dot-length-equals-two

“🖤”.length() => 2
“❤️”.length() => 2
“👦”.length() => 2
“👦🏾”.length() => 4
“🚵‍♀️”.length() => 5
“👨‍👩‍👦‍👦”.length() => 11

한글자로 취급될 것 같은 한개의 이모지에서 이런 결과가 나오는 이유를 찾아보았습니다.

@silverprize
silverprize / reload-loop.md
Last active November 22, 2022 07:47
[macOS] webpack-dev-server reload loop

webpack-dev-server 모듈 기반으로 구성된 프런트엔드 개발환경에서 불시에 페이지 무한 리로드를 발생시키는 문제가 있어 코드를 쫓아가 보았다.
webpack-dev-server -> chokidar -> fsevents 관계로 의존하고 있다.

chokidar 모듈은 파일 시스템 watch를 사용하기 좋게 만든 모듈이고 fsevents 모듈은 macOS 파일시스템 이벤트를 감지하는 모듈이다.
macOS 파일 시스템 이벤트 목록은 아래 링크에서 볼 수 있다.
https://developer.apple.com/documentation/coreservices/1455361-fseventstreameventflags?language=objc
즉, fsevents 모듈은 chokidar 모듈의 엔진이라고 볼 수 있다.

무한 리로드 현상은 위 링크의 이벤트중에서 "kFSEventStreamEventFlagMustScanSubDirs & kFSEventStreamEventFlagKernelDropped" 으로 조합된 이벤트가 발생했을때 시작된다.
macOS는 이 이벤트가 발생하는 원인을 해결할 때까지 이벤트를 계속 보내준다.

@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