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