Skip to content

Instantly share code, notes, and snippets.

View leewin12's full-sized avatar

greg.lee leewin12

View GitHub Profile
@leewin12
leewin12 / split_str.sql
Last active August 29, 2015 13:56 — forked from mikedamage/split_str.sql
MySQL Split User-defined function
-- SPLIT_STR MySQL Function
-- from http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/
CREATE FUNCTION SPLIT_STR(
x VARCHAR(255),
delim VARCHAR(12),
pos INT
)
RETURNS VARCHAR(255)
-- use CHAR_LENGTH instead of LENGTH to support utf8
@leewin12
leewin12 / OneLineJsonSlurper.groovy
Last active August 29, 2015 14:07
Just I try to make it a line.
import groovy.json.JsonSlurper
new JsonSlurper() {
jsonSlurper -> new File('/Users/gregory/be.json').text.split('\n').collect { jsonSlurper.parseText(it).accountId }.unique().each { println it }
}
@leewin12
leewin12 / .htaccess
Last active August 29, 2015 14:08
private IP range config for apache
Order deny,allow
Deny from all
Allow from 10.1.0.0/8
Allow from 172.16.0.0/12
Allow from 192.168.0.0/16
@leewin12
leewin12 / LoggingConfig.groovy
Created March 20, 2015 04:03
Grails 2.4.4 logging with multi environment
// log4j configuration
log4j = {
appenders {
console name: 'stdout', encoder: pattern(conversionPattern: "%d{ISO8601} %p %c{2} %m%n")
appender new DailyRollingFileAppender(
name: 'rollingFileAppender',
file: "logs/cola.log", append: true, datePattern: "'.'yyMMdd",
layout: pattern(conversionPattern: "%d{ISO8601} %p %c{2} %m%n")
)
}
@leewin12
leewin12 / gist:5956083
Last active December 19, 2015 12:39
Play2 post json string and return its value
case class TestObj(name: String, msg: String)
def insertMulti() = Action {
implicit req =>
// parse posted json objs
val json = req.body.asJson.getOrElse(JsNull)
val objs = json.as[List[JsValue]].map {
json => Json.reads[TestObj].reads(json).get
}
// return what we got as json string
@leewin12
leewin12 / asyncHttpClient.groovy
Created January 5, 2015 10:09
Groovy AsyncHttpClient
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.AsyncHTTPBuilder
import groovyx.net.http.URIBuilder
import static groovyx.net.http.Method.POST
import static groovyx.net.http.ContentType.TEXT
import groovy.json.JsonSlurper
def http = new AsyncHTTPBuilder( poolSize:100 )
@leewin12
leewin12 / find_dead.sh
Created August 19, 2016 08:30
check dead ip(or hostname) using shell ping
# !/bin/bash
# ips: ip list file
# ./find_dead.sh > dead.log
# cat dead.log | grep -v ttl | awk '{ print $1 }'
IPS=`cat ips`
for i in $IPS; do
CODE=`ping -c 1 $i `
echo $i $CODE
done
@leewin12
leewin12 / git.migrate
Created September 7, 2016 06:54 — forked from niksumeiko/git.migrate
Moving git repository and all its branches, tags to a new remote repository keeping commits history
#!/bin/bash
# Sometimes you need to move your existing git repository
# to a new remote repository (/new remote origin).
# Here are a simple and quick steps that does exactly this.
#
# Let's assume we call "old repo" the repository you wish
# to move, and "new repo" the one you wish to move to.
#
### Step 1. Make sure you have a local copy of all "old repo"
### branches and tags.
@leewin12
leewin12 / spring-tx-rollback.md
Created December 21, 2018 07:30
Spring transaction의 rollback 처리에 대한 주의사항 정리

요약 @Transactional 처리가 필요한 메소드는, 해당 메소드 내에서 사용되는 모든 메소드에 명시적으로 @Transactional을 처리해주는게 안전하다.

이하 내용

  • Spring JDK Dynamic Proxy는 proxy 처리가 필요가 없거나 (@transactional등), 따로 옵션을 켜주지 않는 한, proxy obj를 만들지 않는다.

  • 따라서 proxy가 없는 class에 대해서는 당연히 tx 영역으로 잡히지 않고, proxy가 없는 외부 class의 method 호출 결과에 대해 try/catch 처리를 할 경우, spring tx manger는 rollback을 하지 않습니다.

  • proxy가 있는 경우에도, 외부 class의 method를 @transactional 없이 호출 할 경우, transactionl이 none으로 인식되어, 호출 결과에 대해 try/catch 처리를 할 경우, spring tx manger는 rollback을 하지 않습니다.

@leewin12
leewin12 / jvm-launch.sh
Created July 17, 2019 02:42
jvm config and nohup without nohup.out
nohup java -jar {{ jvm_config }} -verbose:gc -XX:+UseG1GC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:MetaspaceSize=100M -XX:MaxMetaspaceSize=100M -Xloggc:logs/gc.log -XX:NumberOfGCLogFiles=4 -XX:GCLogFileSize=1M -XX:+UseGCLogFileRotation -Dspring.profiles.active={{ BUILD_PROFILE }} -Dfile.encoding=utf-8 {{ project_name }}.jar 1>/dev/null 2> >(exec nohup logger -t {{ project_name }}) &