Skip to content

Instantly share code, notes, and snippets.

@kwon37xi
kwon37xi / delayedjoin.groovy
Last active December 17, 2015 18:19
Real MySQL http://www.aladin.co.kr/shop/wproduct.aspx?ISBN=8992939000 책의 455 쪽 Delayed Join 이 정말로 성능이 좋아지는지 테스트하는 코드.
@GrabConfig(systemClassLoader=true)
@Grab(group='mysql', module='mysql-connector-java', version='5.1.25')
import groovy.sql.Sql
Sql.withInstance('jdbc:mysql://localhost/employees?useUnicode=true&characterEncoding=utf8',
'root', 'root', 'com.mysql.jdbc.Driver') { sql ->
def times = 1000
def start = 0
print "##### 일반 조인 "
@kwon37xi
kwon37xi / movie_subtitle_match.groovy
Created June 2, 2013 05:37
자막 파일을 동영상 파일 이름에 맞게 순서대로 자동 변경해준다.
/*
동영상 파일과 자막 파일의 이름을 맞춰 준다.
현재 디렉토리에 동영상 파일과 자막 파일의 갯수가 동일해야 한다.
*/
def usage() {
println 'Usage: groovy movie_subtitle_match.groovy 동영상확장자 자막확장자'
println "동영상 파일과 자막 파일의 갯수가 동일해야함"
}
@kwon37xi
kwon37xi / (01장) 기본기.scala
Last active August 15, 2023 06:24
쉽게 배워서 빨리 써먹는 Scala 프로그래밍 연습문제 풀이
/** Chapter 01 **/
/*
문제에 오역이 좀 있다. 아래에서 문제 자체를 검색해서 확인해 볼 것.
Java 7 이상에서 실행할 것.
https://www.google.co.kr/search?client=ubuntu&channel=fs&q=scala+for+the+impatient+exercise&ie=utf-8&oe=utf-8&gws_rd=cr&redir_esc=&ei=oqvrUb-1B6LwiQfjk4GQBg
Scala Doc : http://www.scala-lang.org/api/current/index.html
*/
@kwon37xi
kwon37xi / memcached_keys.php
Created October 7, 2013 04:55
Memcached Key list viewer PHP
<?php
$server = "localhost";
$port = 11211;
/**
* Taken directly from memcache PECL source
*
* http://pecl.php.net/package/memcache
*
*/
@kwon37xi
kwon37xi / CacheLockTest.java
Created October 10, 2013 16:22
Google Guava cache에서 캐시의 특정 키에 값이 없는 상태에서 여러 쓰레드에서 요청이 들어와도 최초 요청 쓰레드 하나만 값을 가져오는 코드를 실행하고, 나머지는 기다렸가가 캐시의 결과를 리턴 받는 것을 시연한다.
package kr.pe.kwonnam.guavatest.cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
/**
@kwon37xi
kwon37xi / screenmargin.py
Last active December 30, 2015 14:09
Linux X Window Screen margin reservation tool.
#!/usr/bin/env python
import gtk
import sys
'''
X Window left/right edge margin reservation tool
Other windows cannot overlap the margin area.
Usage: screenmargin.py left|right pixel
# reserve left side 100 pixel
screenmargin.py left 100
@kwon37xi
kwon37xi / mysqldatetimetest.groovy
Last active February 13, 2018 08:11
MySQL 5.6의 DATETIME ms 반올림 버그와 구버전 JDBC 드라이버의 ms 절삭 버그 조합
/*
MySQL 5.6의 DATETIME 타입에 대한 밀리세컨드 부분 절삭 버그 재현
MySQL 5.6.4 ms 지원 : http://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html
MySQL 5.6 DATETIME 타입에서 ms 반올림(round) 버그 : http://bugs.mysql.com/bug.php?id=68760
MySQL Connector/J 5.1.22 까지는 Date 객체의 ms 부분을 미리 절삭해 전송하는 버그 있음
MySQL Connector/J 5.1.23 부터는 Date 객체의 ms 부분도 함께 전송 -> MySQL 5.6 서버의 ms 반올림 버그 유발 -> 초,분,날짜가 바뀌는 현상 유발
** 아래코드를 반올림 버그가 있는 MySQL 5.6서버에서 JDBC 드라이버 바꿔가며 실행한 결과
@kwon37xi
kwon37xi / NumberBytesUtils.java
Last active August 29, 2015 14:01
Java number / byte arary convert
import java.util.Arrays;
/**
* int 형과 byte[] 간의 변환.
* ByteBuffer 를 사용하는 방법 대신, bit operator를 사용하는 기법.
*
* Java는 기본적으로 BigEndian이다.
*
* 참조
* - http://stackoverflow.com/questions/2383265/convert-4-bytes-to-int
/**
* 쿼리의 IN 처럼 기준 값을 리스트를 받아서 처리하긴 하지만, 너무 큰 리스트는
* 성능에 부담을 주기 때문에 나눠서 실행해야 할 경우, 자동으로 chunkSize에 따라
* 나눠서 호출해주는 유틸리티.
*/
public abstract class ChunkExecutionUtils {
public static final int DEFAULT_CHUNK_SIZE = 1000;
/**
@kwon37xi
kwon37xi / smi_timing.groovy
Created October 27, 2014 15:57
SMI (Video subscript file format) timing sync
if (args.length < 2) {
println "Usage groovy smi_timing filename milliseconds-to-adjust [encoding:default cp949]"
System.exit(-1)
}
def smi = new File(args[0])
def millis = Long.parseLong(args[1])
def encoding = args.length == 3 ? args[2] : "cp949"
println "$smi, $millis, $encoding"