Commons-lang, Commons-io 사용 샘플
문자열의 NULL체크라든가 파일 관리 등의 다양한 기능들을 쉽게 사용할 수 있도록 해줍니다. 기존의 StringUtil이나 TextUtil, FileUtil등을 별도로 만들어 사용하시는 분들은 소스 중복도 없앨 겸 한번 리팩토링 수단으로도 사용해보세요.
아래의 소스는 사용 예들이니 필요한 부분에 사용하시면 도움이 되실 것입니다. 다들 아실것입니다. ^^
1. 샘플 소스
package client;2. 실행 결과
import java.io.File;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
public class CommonClient
{
public static void main(String[] args)
{
String dir = "D:\\temp";
File dirFile = new File(dir);
String[] extensions = {"txt", "html"};
try {
// StringUtils
System.out.println("StringUtils.isEmpty : " +
(StringUtils.isEmpty(null) && StringUtils.isEmpty("")));
System.out.println("StringUtils.isBlank : " +
StringUtils.isBlank(" \n\t"));
System.out.println("StringUtils.substringAfterLast : " +
StringUtils.substringAfterLast("일.이.삼.사", "."));
System.out.println("StringUtils.substringBeforeLast : " +
StringUtils.substringBeforeLast("일.이.삼.사", "."));
String[] splitArr = StringUtils.split("일.이.삼.사", '.');
for (int i = 0, n = splitArr.length; i < n; i++ ) {
System.out.println("split : " + splitArr[i]);
}
System.out.println("StringUtils.leftPad : " +
StringUtils.leftPad("1", 5, '0'));
// FileUtils
// 문자열을 해당 파일에 카피
File file1 = new File(dir, "file1.txt");
String filename = file1.getAbsolutePath();
FileUtils.writeStringToFile(file1,
filename, "UTF-8");
// 파일을 읽어 문자열로 출력
String file1contents = FileUtils.readFileToString(file1, "UTF-8");
System.out.println("file1contents : " + file1contents);
System.out.println("list dir : " +
FileUtils.listFiles(dirFile, extensions, false));
// 해당 문자열을 파일에 저장
File file2 = new File(dir, "file2.txt");
String filename2 = file2.getAbsolutePath();
FileUtils.writeStringToFile(file2, filename2,
"UTF-8");
String file2contents =
FileUtils.readFileToString(file2, "UTF-8");
System.out.println("file2contents : " + file2contents);
// 디렉토리 강제 할당
File testFile = new File(dir, "subdir");
FileUtils.forceMkdir(testFile);
System.out.println("list dir : " +
FileUtils.listFiles(testFile,
extensions, false));
// 파일 카피
File testFile2 = new File(dir, "testFile1Copy.txt");
File testFile1 = new File(dir, "testFile1.txt");
FileUtils.copyFile(testFile1, testFile2);
//IOUtils.copy(inputStream, outputStream); 와 같음
FileUtils.forceDelete(testFile2);
System.out.println("list dir : " +
FileUtils.listFiles(dirFile, extensions, false));
File directory = new File(dir, "subdir");
FileUtils.copyFileToDirectory(testFile1, directory);
// 파일 읽어서 문자열로 리턴
String readFile = FileUtils.readFileToString(file1, "UTF-8");
//String readFile = IOUtils.toString(inputStream);
System.out.println("readFile : " + readFile);
// 라인 별로 파일 내용 읽기
List<String> readList = FileUtils.readLines(file1, "UTF-8");
//List<String> readList = IOUtils.readLines(inputStream);
for (int j = 0, sl = readList.size(); j < sl ; j++) {
System.out.println("readList : " + readList.get(j));
}
long size = FileUtils.sizeOfDirectory(dirFile);
System.out.println(size + " bytes");
System.out.println(FileUtils.byteCountToDisplaySize(size));
} catch (Throwable e) {
e.printStackTrace();
}
}
}
jQuery를 활용한 Key Bind
1. 필요한 Javascript
- wget http://js-hotkeys.googlecode.com/files/jquery.hotkeys-0.7.8.js
2. 사용 예
$(document).bind('keydown', 'Ctrl+c', function(){ alert('copy?');});
3. 데모 사이트
- 여기를 클릭해보세요.
- 지원 브라우저 : IE5/6/7, FF, Opera, Chrome
[참고 사이트]
[북 리뷰] 1일 30분
[책 내용]
1장 . 인생은 공부한 사람이 승리한다.
01. 공부에는 타이밍이 굉장이 중요하다.
02. 날마다 조금씩 꾸준히 가늘고 길게 공부하라. : 1일 30분씩이라도 꾸준함이 중요하다고 함
03. 책은 한 권씩 산다.
04. 반복 학습이 가장 효율적인 공부법이다. : 학습 - 1주후에 복습 - 2주후에 2회째 복습 - 1개월내 3회째 복습을 통해 장기 기억이 됨을 활용
05. 공부성과를 좌우하는 가장 큰 요소는 시간이다. : (공부성과)=(교재와 서비스 질)*(집중력)*(공부시간)^2+(과거의공부량) : 학습 시간의 중요성 언급
06. 이기는 공부습관 : 교재와 서비스 질 (20%) + 공부의 양 (80%) = 100%
07. 공부성과는 곧바로 나타나지 않는다. : 꾸준함을 강조함
08. 자기투자가 최고의 투자이다. : 자기 자신이 배운 지식을 타인에게 가르쳐주면 흡수력이 훨씬 상승함
09. 자기 투자를 게을리 하면 5년 후가 위험하다.
10. 자기투자는 수년 후 큰 결실로 돌아온다.
2장. 시간 관리가 공부의 핵심이다.
11. TV를 보지 않으면 2개월의 시간을 벌 수 있다.
12. 야근 시간을 적극 활용하라.
13. 업무 처리 속도를 높인다.
14. 돈은 공부 시간과 장소 확보를 위한 비용이다.
15. ‘5분도 낭비할 수 없다’는 의지가 중요하다. : 출퇴근 시간 활용, 능률을 높이는 학습 방법 선택
16. 음성을 이용하면 죽은 시간을 살릴 수 있다.
17. 휴일을 적극 활용한다.
18. 가능하면 아침형 인간이되라.
3장. 문제는 집중력이다.
19. 컨디션이 좋아야 직중력도 높아진다.
20. 마지못해 하는 공부는 뇌에 고통을 줄 뿐이다.
21. 30분 공부, 15분 휴식을 기본으로 한다. : 싫증을 느끼기전에 미리 쉬어야 한다
22. 독서는 최고의 휴식이다.
23. 집중력이 떨어지면 즉시 공부를 그만둬라 : 장소, 내용의 변화를 줘가면서 학습하는 습관을 가져라
24. 목표만 명확하다면 쉬는건 문제가 아니다.
4장 단기집중형, 장기계획형의 학습법
25. 단기 집중형의 공부 요령
26. 단기 집중형이 실패가 많은 이유. : "막상 닥쳐야 집중할수있다" 며 소중한 시간을 낭비하는 예가 많음
27. 나의 유학을 성공시킨 장지 계획형 공부법
28. ‘고독’이 공부의 최대 적이다.
5장. 노력하는 사람을 위한 영어 학습법
29. 영어 공부를 꾸준히 하고 있지만 성과는 없다.
30. 왜 영어 실력이 늘지 않을까?(1) : 공부의 질을 잘못 선택
31. 왜 영어 실력이 늘지 않을까?(2) : 지속적인 학습이 중요함
32. 노력하는 사람을 위한 영어 학습법.
회화편
- 원어민이 자주 사용하는 문장을 통째로 암기
- TV 드라마 시리즈를 활용하라 Example > friends -> Role Playing
듣기편
- TV 드라마 시리즈를 많이 보면서 기본 문장 암기량을 늘리는 방법
듣기&보기
- 영어 자막으로 듣기 학습
발음의 습득
- 듣기가 안되는 사람은 듣기 연습을 하기보다 발음 연습을 함
연음
- 대명사나 전치사의 강형,약형 동화 결합 탈락
독해
- 쉬운 영어 문장을 빠르게 독해하는 기술
- 자신이 흥미를 느끼는 분야 혹은 일 관련 분야의 영문을 매일 30분 읽기
작문
- 첨삭을 받아야함
33. 학습량 부족이 가장 큰 원인이다.
6장. 계획을 세우는 것이 공부의 절반이다
34. 목표가 명확할 때 성공 확률이 높아진다.
35. 일정표를 만들어보이는 곳에 둬라
36. 목표는 무리하지 않게 설정한다
37. 반드시 종이에 목표를 써 붙여둔다. : 1일 목표는 시간 단위로 설정함
38. 목표가 명확하면 행동이 변한다
39. 결단이 반이다 : 모든 시행착오의 원인은 결단을 못내는데서 부터 비롯된다.
40. 생각을 바꿔야 목표를 달성할수있다
41. 목표를 이루기 위해서는 희생이 필요하다
42. 수첩을 활용하면 실현 속도가 빨라진다
43. 당신이 성공하는 수첩 활용법
7장. 학습효율을 높이기 위한 식사와 수면
44. 식사와 공부 성과의 관계 : 과식을 하지 않고 야채와 밥을 중심으로 식사하고 식사 간격을 12시, 3시, 6시 등 3시간 이상으로 함. 식사 - 목욕 - 공부
45. 효과적인 수면이 기억을 촉진한다 : 하루에 최소한 6시간은 잠을자야하고, 이상적인 수면시간은 7시간 30분
46. 자명종 없이 잠에서 깨는 방법 : 잠을 잘때 커튼을 치지 마라
47. 이른 아침 뇌를 깨워라 : 일어나자마자 따듯한 물로 샤워을 해라.
8장. 학습효율을 높여주는 도구
48. 타이머가 집중력을 가져온다
49. 외출할 때는 귀마개와 클립보드가 무기이다
50. 볼펜 하나에도 신경 쓴다 : 파일로트 PILOT 닥터그립 Dr.Grip 1.0
51. 영어 실력 향상에는 좋은 도구가 필요하다 : 노이즈 캔슬링 헤드폰 MDR-NC11, Ipod - Mp3 공부(영어 디지털북)
52. 의자에 제일 먼저 투자해야한다 : 허먼밀러 Hermanmiller 사의 ‘에어론 체어 Aaron-Chair'
53. 최적의 조명 상태를 유지한다.
54. 머리는 차게, 발은 따듯하게 한다
55. 상쾌한 기상을 돕는 도구. : National 생체리듬 광,알림스탠드, 카시오,타이멕스 등 발매 카시오 G-Shock G-7500-1JE
[느낀점]
- 목표를 가지고 지속적으로 목표를 위해 반복하는 생활이 무엇보다 중요하고, 그것을 기록하는 습관이 주효함
- 나름 평범한 일반인들에게 발전적인 인생을 살 수 있는 바로미터(지침)가 됨.
- 또 한번 느끼는 일본인의 기록하는 습관에 감탄함
- 자신에 투자하라
- 가볍게 읽을 수 있는 분량이지만 실천하기에 많은 노력과 습관이 필요함
jquery를 활용한 문자열 길이 제한
1. jquery 다운 로드
2. 사용 소스 설명
/ textarea id, 제한 글자 수, 입력 결과 메세지 저장 ID- 사용 코드
function limitCharacters(textid, limit, limitid)
{
// 잆력 값 저장
var text = $('#'+textid).val();
// 입력값 길이 저장
var textlength = text.length;
if(textlength > limit)
{
$('#' + limitid).html('글내용을 '+limit+
'자 이상 쓸수 없습니다!');
// 제한 글자 길이만큼 값 재 저장
$('#'+textid).val(text.substr(0,limit));
return false;
}
else
{
$('#' + limitid).html('쓸수 있는 글자가 '+ (limit - textlength) +
' 자 남았습니다.');
return true;
}
}
$(function(){
$('#contents').keyup(function(){
limitCharacters('contents', 20, 'charlimitid');
})
});
3. 데모
- 지원 브라우저 : IE5/6/7, FF, Opera, Chrome
log4jdbc를 활용하여 쿼리 로그 남기기
- log4jdbc3-1.1.jar(If you are using JDK 1.4 or 1.5, you should use the JDBC 3 version of log4jdbc.)
- slf4j-api-1.5.0.jar(log4jdbc와 logging 서비스 연동을 위한 API 제공)
- slf4j-log4j12-1.5.2.jar(log4jdbc와 Log4j 기반의 Logging 서비스 연동을 위한 구현 라이브러리 제공)
2. DataSource 서비스 속성 정의 파일 정의
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"3. Logger 정의
destroy-method="close">
<property name="driverClassName"
value="net.sf.log4jdbc.DriverSpy"/>
<property name="url"
value="jdbc:log4jdbc:mysql://localhost:3306/member?useUnicode=true
&characterEncoding=utf8"/>
<property name="username" value="member"/>
<property name="password" value="member"/>
<property name="maxActive" value="30"/>
<property name="maxIdle" value="3"/>
<property name="maxWait" value="-1"/>
</bean>
- jdbc.sqlonly : SQL문만을 로그로 남기며, PreparedStatement일 경우 관련된 argument 값으로 대체된 SQL문이 보여진다.
- jdbc.sqltiming : SQL문과 해당 SQL을 실행시키는데 수행된 시간 정보(milliseconds)를 포함한다.
- jdbc.audit : ResultSet을 제외한 모든 JDBC 호출 정보를 로그로 남긴다. 많은 양의 로그가 생성되므로 특별히 JDBC 문제를 추적해야 할 필요가 있는 경우를 제외하고는 사용을 권장하지 않는다.
- jdbc.resultset : ResultSet을 포함한 모든 JDBC 호출 정보를 로그로 남기므로 매우 방대한 양의 로그가 생성된다.
- 예) log4j.xml
<?xml version="1.0" encoding="UTF-8"?>4. 로그 처리 결과
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %5p [%c] %m%n" />
</layout>
</appender>
<appender name="rollingFile"
class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\logs\\error\\error.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="100MB"/>
<param name="MaxBackupIndex" value="2"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c]-%m%n" />
</layout>
</appender>
<logger name="org.springframework.jdbc">
<level value="DEBUG"/>
<appender-ref ref="console"/>
</logger>
<logger name="com.mimul">
<level value="DEBUG"/>
<appender-ref ref="console"/>
<appender-ref ref="rollingFile"/>
</logger>
<logger name="org.apache.struts">
<level value="DEBUG"/>
<appender-ref ref="console"/>
<appender-ref ref="rollingFile"/>
</logger>
<!-- log SQL (pre-execution) plus exceptions caused by SQL -->
<logger name="jdbc.sqlonly" additivity="false">
<level value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="rollingFile"/>
</logger>
<!-- log SQL with timing information, post execution -->
<logger name="jdbc.sqltiming" additivity="false">
<level value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="rollingFile"/>
</logger>
<!-- only use the two logs below to trace ALL JDBC information,
NOTE: This can be very voluminous! -->
<!-- log all jdbc calls except ResultSet calls -->
<logger name="jdbc.audit" additivity="false">
<level value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="rollingFile"/>
</logger>
<!-- log the jdbc ResultSet calls -->
<logger name="jdbc.resultset" additivity="false">
<level value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="rollingFile"/>
</logger>
<!-- this log is for internal debugging of log4jdbc, itself -->
<!-- debug logging for log4jdbc itself -->
<logger name="log4jdbc.debug" additivity="false">
<level value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="rollingFile"/>
</logger>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
<appender-ref ref="rollingFile"/>
</root>
</log4j:configuration>
2008-10-24 10:23:02 [jdbc.audit] - <2. Connection.setAutoCommit(true)
2008-10-24 10:23:02 [java.sql.Connection] - <{conn-100003} Connection>
2008-10-24 10:23:02 [java.sql.Connection] - <{conn-100003}
Preparing Statement:
select count(userid) as total from MEMBER where userid = ?
and password = ? >
2008-10-24 10:23:02 [jdbc.audit] -
<2. Connection.prepareStatement(
select count(userid) as total from MEMBER where
userid = ? and password = ? )
2008-10-24 10:23:02 [jdbc.audit] -
<2. PreparedStatement.setQueryTimeout(0)
2008-10-24 10:23:02 [jdbc.audit] -
<2. PreparedStatement.setString(1, "pepsi")
2008-10-24 10:23:02 [jdbc.audit] -
<2. PreparedStatement.setString(2, "1234")
2008-10-24 10:23:02 [java.sql.PreparedStatement] -
<{pstm-100004}
Executing Statement:
select count(userid) as total from MEMBER where userid = ? and password = ? >
2008-10-24 10:23:02 [java.sql.PreparedStatement]
- <{pstm-100004}
Parameters: [pepsi, 1234]>
2008-10-24 10:23:02,281 DEBUG [java.sql.PreparedStatement] -
<{pstm-100004} Types: [java.lang.String, java.lang.String]>
2008-10-24 10:23:02,281 DEBUG [jdbc.sqlonly] -
<2. select count(userid) as total from MEMBER where userid = 'pepsi'
and password = '1234' >
2008-10-24 10:23:02,281 DEBUG [jdbc.sqltiming] -
<2. select count(userid) as total from MEMBER where userid = 'pepsi'
and password = '1234'
{executed in 0 msec}>
2008-10-24 10:23:02 [jdbc.audit] - <2. PreparedStatement.execute()
2008-10-24 10:23:02 [jdbc.audit] - <2. PreparedStatement.getResultSet()
2008-10-24 10:23:02 [java.sql.ResultSet] - <{rset-100005} ResultSet>
2008-10-24 10:23:02 [jdbc.resultset] - <2. ResultSet.getType()
2008-10-24 10:23:02 [jdbc.resultset] - <2. ResultSet.next() returned true
2008-10-24 10:23:02 [jdbc.resultset] - <2. ResultSet.getMetaData() returned
2008-10-24 10:23:02 [jdbc.resultset] - <2. ResultSet.getInt(TOTAL) returned 1
2008-10-24 10:23:02 [jdbc.resultset] - <2. ResultSet.wasNull() returned false
2008-10-24 10:23:02 [jdbc.resultset] - <2. ResultSet.next() returned false
2008-10-24 10:23:02, [java.sql.ResultSet] - <{rset-100005} Header: [TOTAL]>
2008-10-24 10:23:02 [java.sql.ResultSet] - <{rset-100005} Result: [1]>
2008-10-24 10:23:02 [jdbc.audit] - <2. Connection.getMetaData()
2008-10-24 10:23:02 [jdbc.resultset] - <2. ResultSet.close()
2008-10-24 10:23:02 [jdbc.audit] - <2. PreparedStatement.close()
2008-10-24 10:23:02 [jdbc.audit] - <2. Connection.isClosed()
2008-10-24 10:23:02 [jdbc.audit] - <2. Connection.getAutoCommit()
2008-10-24 10:23:02 [jdbc.audit] - <2. Connection.clearWarnings()
2008-10-24 10:23:02 [jdbc.audit] - <2. Connection.setAutoCommit(true)
jdbc.sqltiming 로그에 보면 실행된 FULL Query가 보일 것입니다. 굿 럭!!
가트너 2009년 10대 전략 기술 발표

① 가상화(Virtualization)
▷ 현재 서버 가상화를 중심으로 진행되고 있으나, 향후에는 스토리지와 고객 장치 가상화, 호스티드 가상 이미지(hosted virtual image) 등으로 발달할 것
② 클라우드 컴퓨팅(Cloud Computing)
▷ 클라우드 컴퓨팅의 활용으로 기업들은 시장 진입시 비용절감, 탄력적 운영등이가능해질 것
③ 서버(Servers-Beyond Blades)
▷ 서버는 현재 블레이드 서버(blade server) 단계에서 더 진화할 것
④ 웹기반 아키텍처(Web-Oriented Architectures)
▷ 웹 중심 방식이 지속적으로 진화함에 따라 전사 솔루션에 활용할 수 있을 것
⑤ 엔터프라이즈 매쉬업(Enterprise Mashups)
▷ 기업들은 현재 웹상에서의 취미부터 전사 시스템에 이르기까지 매쉬업을 이용한 애플리케이션을 전달 및 관리하기 위한 모델을 연구
⑥ 특화시스템(Specialized Systems)
▷ 혼합형 시스템(heterogeneous systems)은 가장 어려운 작업의 요구사항을 처리하기 위해 새롭게 떠오르는 고성능 컴퓨팅 트렌드로서, 향후 컴퓨팅 시장에 확산될 것
⑦ 소셜 소프트웨어 및 소셜 네트워킹(Social Software and Social Networking)
▷ 소셜 소프트웨어는 사회적 네트워킹, 사회적 협력, 사회적 매체 및 사회적 증명 등 다양한 종류의 기술을 포함함에 따라, 기업은 사회적 플랫폼을 채택해야 할 것
⑧ 통합통신(Unified Communications)
▷ 애플리케이션 서버의 용량이 증가하고 통신 애플리케이션이 공통 상용 서버(common off-the-shelf servers)와 운영체계로 변화함에 따라 시장들이 통합 될 것
⑨ 비즈니스 인텔리전스(Business Intelligence)
▷ 비즈니스 인텔리전스(BI)는 기업 전략부터 운영 과정에 이르는 모든 비즈니스 단계에 영향력을 미치며, 임무 달성 능력을 향상시킬 것
⑩ 그린IT(Green IT)
▷ 사용 증가로 인한 탄소 배출, 기타 환경적 영향에 대한 규제가 강화됨에 따라 기업들은 데이터 센터의 능력 향상 및 그린IT를 위한 대응방안을 마련해야 할 것
[참고 사이트]
- http://www.itglobal.or.kr/v1/globalIT/%EA%B0%80%ED%8A%B8%EB%84%88-2009%EB%85%84-10%EB%8C%80-%EC%A0%84%EB%9E%B5-%EA%B8%B0%EC%88%A0-%EB%B0%9C%ED%91%9C
OAuth ?
OAuth는 한 어플리케이션이 다른 어플리케이션에서 관리하는 사용자 정보를 접근할 수 있는 표준화된 방법을 제공하는 스펙입니다
Open Platforms와 Open API에서 접목되어 사용됩니다. 그래서 mashup 사이트를 하기 위한 Open 인증(권한 인가) API의 하나로 Oauth 표준을 적용하는 사이트들이 많아지고 있습니다.
예로 Netflix, Threadless, Bloglines, Twitter, Jaiku, Ma.gnolia, Springnote 등이 OAuth를 지원한다는 군요.
그리고 또한 개별 사이트에서 진행되고 있는 Google AuthSub, AOL OpenAuth, Yahoo BBAuth 등등도 있답니다. 개별 사이트에 독자적인 방법이죠.
아래는 인증 절차의 이해를 돕기위한 그림입니다. 이그림이 오히려 스펙을 이해하는데 도움이 많이 됩니다. 역시 문자보다는 그림이 가독성이 뛰어나죠 ^^

[Implementing OAuth]
오늘의 경제 상황
아르헨티나는 290억달러 규모 민간 연금펀드를 국유화하는 결정을 내림으로써 7년 만에 두 번째 국가부도를 맞을 위험에 처한 것으로 전해지고 있다.
코스피 1049, 코스닥 308
바닥이 안보이는 안개 정국입니다. ^^
통계용 CRON 스크립트
mysql DB를 활용하여 일간, 월간 통계를 생성하는 스크립트입니다.
mysql 5.1에서 필요한 프로시져를 만들었고 그 프로시져를 하루에 한번 00시에 호출하여 통계 데이터를 집어 넣는 스크립트입니다.
1. 스크립트 소스(00-statistics.sh)
#!/bin/sh
# 계정 정보
USERNAME="root"
PASSWORD="mimulxxxxxx"
DBHOST="localhost"
TODATE=`/bin/date "+%Y%m%d"`
TOMONTH=`/bin/date "+%Y%m"`
PREVDATE=`/home/k2/bin/getPrevDate`
TODAY_DD=`/bin/date | /bin/awk '{print $3}'`
PREVMONTH=`/home/k2/bin/getPreMonth`
#실행 커맨드
mysql="/home/k2/server/mysql/bin/mysql --user=$USERNAME
--password=$PASSWORD --host=$DBHOST member"
statinmonthlysignup="call statinmonthlysignup
('${TOMONTH}', '${PREVMONTH}', @out_status1);"
statinmonthlysignin="call statinmonthlysignin
('${TOMONTH}', '${PREVMONTH}', @out_status2);"
statinmonthlysiteinfo="call statinmonthlysiteinfo
('${TOMONTH}', '${PREVMONTH}', @out_status3);"
statindailysignup="call statindailysignup
('${TODATE}', '${PREVDATE}', @out_status1);"
statindailysignin="call statindailysignin
('${TODATE}', '${PREVDATE}', @out_status2);"
statindailysiteinfo="call statindailysiteinfo
('${TODATE}', '${PREVDATE}', @out_status3);"
# 로그 설정
LOG=/home/k2/sql/mysql_statistics_`/bin/date '+%Y%m%d'`.log
#매월 1일인지 체크
if [ $TODAY_DD = 1 ]
then
# 월별 가입자 통계
echo "$TOMONTH $PREVMONTH Monthly Signup Start..." >> $LOG
if ! $mysql -e "$statinmonthlysignup" 1>/dev/null 2>/dev/null;
then
echo "$statinmonthlysignup Daily Signup Abnormal End...." >> $LOG
else
echo "Monthly Signup Normal End...." >> $LOG
fi
# 월별 로그인 통계
echo "$TOMONTH $PREVMONTH Monthly Signin Start..." >> $LOG
if ! $mysql -e "$statinmonthlysignin" 1>/dev/null 2>/dev/null;
then
echo "$statinmonthlysignin
Monthly Signin Abnormal End...." >> $LOG
else
echo "Monthly Signin Normal End...." >> $LOG
fi
# 월별 사이트 통계
echo "$TOMONTH $PREVMONTH Monthly Siteinfo Start..." >> $LOG
if ! $mysql -e "$statinmonthlysiteinfo" 1>/dev/null 2>/dev/null;
then
echo "$statinmonthlysiteinfo Monthly Siteinfo Abnormal End...." >> $LOG
else
echo "Monthly Siteinfo Normal End...." >> $LOG
fi
fi
# 일별 가입자 통계
echo "$TODATE $PREVDATE Daily Signup Start..." >> $LOG
if ! $mysql -e "$statindailysignup" 1>/dev/null 2>/dev/null;
then
echo "$statindailysignup Daily Signup Abnormal End...." >> $LOG
else
echo "Daily Signup Normal End...." >> $LOG
fi
# 일별 로그인 통계
echo "$TODATE $PREVDATE Daily Signin Start..." >> $LOG
if ! $mysql -e "$statindailysignin" 1>/dev/null 2>/dev/null;
then
echo "$statindailysignin Daily Signin Abnormal End...." >> $LOG
else
echo "Daily Signin Normal End...." >> $LOG
fi
# 일별 사이트 통계
echo "$TODATE $PREVDATE Daily Siteinfo Start..." >> $LOG
if ! $mysql -e "$statindailysiteinfo" 1>/dev/null 2>/dev/null;
then
echo "$statindailysiteinfo Daily Siteinfo Abnormal End...." >> $LOG
else
echo "Daily Siteinfo Normal End...." >> $LOG
fi
2. CRON 등록
# 통계용 CRON
0 0 * * * /home/k2/sql/00-statistics.sh > /dev/null 2>&1
Top 84 MySQL Performance Tips
- Kaj (Most Excellent Obvious Facilitator) Index stuff.
- Ronald Don’t Index Everything
- Use benchmarking
- Minimize traffic by fetching only what you need.
- Paging/chunked data retrieval to limit
- Don’t use SELECT *
- Be wary of lots of small quick queries if a longer query can be more efficient
- Use EXPLAIN to profile the query execution plan
- Use Slow Query Log (always have it on!)
- Don’t use DISTINCT when you have or could use GROUP BY
- Use proper data partitions
- For Cluster. Start thinking about Cluster *before* you need them
- Insert performance
- Batch INSERT and REPLACE
- Use LOAD DATA instead of INSERT
- LIMIT m,n may not be as fast as it sounds
- Don’t use ORDER BY RAND() if you have > ~2K records
- Use SQL_NO_CACHE when you are SELECTing frequently updated data or large sets of data
- avoid wildcards at the start of LIKE queries
- avoid correlated subqueries and in select and where clause (try to avoid in)
- config params –
- no calculated comparisons — isolate indexed columns
- innodb_flush_commit=0 can help slave lag
- ORDER BY and LIMIT work best with equalities and covered indexes
- isolate workloads don’t let administrative work interfere with customer performance. (ie backups)
- use optimistic locking, not pessimistic locking. try to use shared lock, not exclusive lock. share mode vs. FOR UPDATE
- use row-level instead of table-level locking for OLTP workloads
- Know your storage engines and what performs best for your needs, know that different ones exist.
- use MERGE tables ARCHIVE tables for logs
- Optimize for data types, use consistent data types. Use PROCEDURE ANALYSE() to help determine if you need less
- separate text/blobs from metadata, don’t put text/blobs in results if you don’t need them
- if you can, compress text/blobs
- compress static data
- don’t back up static data as often
- derived tables (subqueries in the FROM clause) can be useful for retrieving BLOBs w/out sorting them. (self-join can speed up a query if 1st part finds the IDs and use it to fetch the rest)
- enable and increase the query and buffer caches if appropriate
- ALTER TABLE…ORDER BY can take chronological data and re-order it by a different field
- InnoDB ALWAYS keeps the primary key as part of each index, so do not make the primary key very large, be careful of redundant columns in an index, and this can make the query faster
- Do not duplicate indexes
- Utilize different storage engines on master/slave ie, if you need fulltext indexing on a table.
- BLACKHOLE engine and replication is much faster than FEDERATED tables for things like logs.
- Design sane query schemas. don’t be afraid of table joins, often they are faster than denormalization
- Don’t use boolean flags
- Use a clever key and ORDER BY instead of MAX
- Keep the database host as clean as possible. Do you really need a windowing system on that server?
- Utilize the strengths of the OS
- Hire a MySQL ™ Certified DBA
- Know that there are many consulting companies out there that can help, as well as MySQL’s Professional Services.
- Config variables & tips:
- use one of the supplied config files
- key_buffer, unix cache (leave some RAM free), per-connection variables, innodb memory variables
- be aware of global vs. per-connection variables
- check SHOW STATUS and SHOW VARIABLES (GLOBAL|SESSION in 5.0 and up)
- be aware of swapping esp. with Linux, “swappiness” (bypass OS filecache for innodb data files, innodb_flush_method=O_DIRECT if possible (this is also OS specific))
- defragment tables, rebuild indexes, do table maintenance
- If you use innodb_flush_txn_commit=1, use a battery-backed hardware cache write controller
- more RAM is good so faster disk speed
- use 64-bit architectures
- Know when to split a complex query and join smaller ones
- Debugging sucks, testing rocks!
- Delete small amounts at a time if you can
- Archive old data — don’t be a pack-rat! 2 common engines for this are ARCHIVE tables and MERGE tables
- use INET_ATON and INET_NTOA for IP addresses, not char or varchar
- make it a habit to REVERSE() email addresses, so you can easily search domains
- –skip-name-resolve
- increase myisam_sort_buffer_size to optimize large inserts (this is a per-connection variable)
- look up memory tuning parameter for on-insert caching
- increase temp table size in a data warehousing environment (default is 32Mb) so it doesn’t write to disk (also constrained by max_heap_table_size, default 16Mb)
- Normalize first, and denormalize where appropriate.
- Databases are not spreadsheets, even though Access really really looks like one. Then again, Access isn’t a real database
- In 5.1 BOOL/BIT NOT NULL type is 1 bit, in previous versions it’s 1 byte.
- A NULL data type can take more room to store than NOT NULL
- Choose appropriate character sets & collations — UTF16 will store each character in 2 bytes, whether it needs it or not, latin1 is faster than UTF8.
- make similar queries consistent so cache is used
- Have good SQL query standards
- Don’t use deprecated features
- Use Triggers wisely
- Run in SQL_MODE=STRICT to help identify warnings
- Turning OR on multiple index fields (<5.0) into UNION may speed things up (with LIMIT), after 5.0 the index_merge should pick stuff up.
- /tmp dir on battery-backed write cache
- consider battery-backed RAM for innodb logfiles
- use min_rows and max_rows to specify approximate data size so space can be pre-allocated and reference points can be calculated.
- as your data grows, indexing may change (cardinality and selectivity change). Structuring may want to change. Make your schema as modular as your code. Make your code able to scale. Plan and embrace change, and get developers to do the same.
- pare down cron scripts
- create a test environment
- try out a few schemas and storage engines in your test environment before picking one.
- Use HASH indexing for indexing across columns with similar data prefixes
- Use myisam_pack_keys for int data
- Don’t use COUNT * on Innodb tables for every search, do it a few times and/or summary tables, or if you need it for the total # of rows, use SQL_CALC_FOUND_ROWS and SELECT FOUND_ROWS()
- use –safe-updates for client
- Redundant data is redundant
- Use INSERT … ON DUPLICATE KEY update (INSERT IGNORE) to avoid having to SELECT
- use groupwise maximum instead of subqueries
- be able to change your schema without ruining functionality of your code
- source control schema and config files
- for LVM innodb backups, restore to a different instance of MySQL so Innodb can roll forward
- use multi_query if appropriate to reduce round-trips
- partition appropriately
- partition your database when you have real data
- segregate tables/databases that benefit from different configuration variables
[참고 사이트]
Cross Browser Word Breaker with jQuery
| 속성 | Internet Explorer 5이상 | Safari 3이상/Chrome |
|---|---|---|
| normal | ○ | ○ |
| keep-all | ○ | × |
| break-all | ○ | ○ |
2. IE6, 7 적용 방안
- class 나 style="word-break:break-all;" 식의 인라인 스타일
3. Firefox에서 임시 방편으로 적용 방안
- overflow:hidden으로 사용하면 박스 레이아웃을 유지할 수 있음
- 스크롤바가 하위에 생겨서 보기 싫음
4. jQuery를 활용한 Cross Browser애서 사용
- FireFox나 Opera에서는 word-break:break-all 스타일이 비표준이라서 허용되지 않음
- 다른 방법이 필요
- Usage: $('[search]').breakWords();
- 소스
(function($) {
$.fn.breakWords = function() {
this.each(function() {
if(this.nodeType !== 1) { return; }
if(this.currentStyle
&& typeof this.currentStyle.wordBreak === 'string') {
this.runtimeStyle.wordBreak = 'break-all';
}
else if(document.createTreeWalker) {
var trim = function(str) {
str = str.replace(/^\s\s*/, '');
var ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
};
//For Opera, Safari, and Firefox
var dWalker = document.createTreeWalker(this,
NodeFilter.SHOW_TEXT, null, false);
var node,s,c = String.fromCharCode('8203');
while (dWalker.nextNode()) {
node = dWalker.currentNode;
s = trim( node.nodeValue ).split('').join(c);
node.nodeValue = s;
}
}
});
return this;
};
})(jQuery);
[참고 사이트]
- http://blog.stchur.com/2007/02/22/emulating-css-word-wrap-for-mozillafirefox/
- http://snippets.dzone.com/posts/show/6271
- http://www.hedgerwow.com/360/dhtml/css-word-break.html
- http://blog.stevenlevithan.com/archives/faster-trim-javascript
jQuery 기반의 BlockUI 구현
1. 필요한 라이브러리
- jquery-1.2.6.js
- jquery.blockUI.js
2. 구현 된 소스
<!DOCTYPE HTML PUBLIC "-//W3C//DTD
HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>jQuery BlockUI</title>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript" src="jquery.blockUI.js"></script>
<script type="text/javascript"> $(function() {
$('#test').click(function() {
$.blockUI({ message: $('#question'), css: { width: '275px' } });
});
$('#yes').click(function() {
// update the block message
$.blockUI({ message: "<h1>^^...</h1>" });
$.ajax({
url: 'wait.jsp',
cache: false,
complete: function() {
// unblock when remote call returns
$.unblockUI();
}
});
});
$('#no').click(function() {
$.unblockUI();
return false;
});
});
</script>
<body>
<input id="test" type="submit" value="Show Dialog" />
<div id="question" style="display:none; cursor: default">
<h1>Would you like to contine?.</h1>
<input type="button" id="yes" value="Yes" />
<input type="button" id="no" value="No" />
</div>
</body>
</html>
3. 데모
- http://mimul.com/examples/Block/jQueryBlock.html
4. 기타
- prototype기반의 BlockUI - http://prototype-window.xilinus.com/themes.html
word clouds
자신의 사이트 Feed 주소를 넣어거 아님 자신이 자주 사용하는 태그나 단어를 넣고 생성할 수도 있습니다. 아래 그림은 제가 만들어본 Clouds입니다.
[참고 사이트]
- http://wordle.net/
mysql 백업 스크립트
원격 서버든, 로컬 서버든 mysql 백업 스크립트가 필요하죠. 필요하신 분 참고하세요.
#!/bin/sh
# 백업 테이블
TABLES="member_user member_auth member_site"
# mysqldump & mysql options DB="member" RHOST="211.202.77.80" LHOST="localhost" USER="memberuser" PASS="memberadmin" DUMPOPTS="--insert-ignore --quote-names --no-create-info
--default-character-set=utf8 $DB -h ${RHOST}
--user ${USER} --password=${PASS}" LSQLOPTS="-h${lhost} -u${user} -p${pass}" RSQLOPTS="-h${rhost} -u${user} -p${pass}"
# 로그 설정
LOG=/logs/mysql_backup_`date +%m%d%Y`.log
# DUMPDBB
DUMPDB=member_2008.sql
for table in $TABLES;
do
echo "dumping $table ..." >> $LOG
mysqldump $DUMPOPTS $table >> $DUMPDB 2>>$LOG
echo "$table dumped!" >> $LOG
done
Service Oriented Architectures (SoA) for convergent Service Delivery Platforms (SDPs)
SDP에 SOA 적용에 대한 논문이 두개 나왔습니다.
SDP란 새로운 Convergence 멀티미디어 서비스를 빠른 개발과 적용을 위해서 고안된 새로운 아키텍처가 SP라고 합니다. 그리고 SDP는 서비스의 생성 환경, 실행, 관리 환경에 필요한 주요한 기능들을 제공합니다. 여기서 서비스란 IPTV 등의 멀티미디어 콘텐츠 유통, 과금, 기존의 TelCo 인프라와 연계 등의 다양한 아키텍처로 응용되고 있답니다.
아래 두 논문의 내용을 보면..
- 웹 서비스 기술에 대한 중요한 가능성에 대한 리뷰를 실었고
- Service Layer Architecture
- SOA는 기술적, 비즈니스 관점에서 서비스 지향의 관점을 보여주었고
- SOA기반의 SDP의 특징들을 제시했고
- Service Layer에서 SDP와 OSS 사이에서의 상호 연동을 단순화 할 수 있는 점을 평가했고
- Service Layer에서 SOA 관점에서 영향, 이슈를 점검했고
- 통신 운영자들을 위한 SOA에 대한 의미를 정의
했다고 합니다.
한번 살펴보세요.. 통신 회사에서 SDP라는 아카텍처 시스템이 SOA를 반영하고 있다고 합니다. 저희 나라 KT, KTF, SK Telecom에서도 필요한 아키텍처를 도입 및 운영하고 있겠죠?
아래 두 링크를 통해 논문을 다운 받으세요.
- Service oriented architectures and telcos
- Applying service oriented architectures to service delivery platforms
직장인의 변화무쌍한 심리상태
- Boss is not here(상사가 없을때):

- Boss is calling(상사가 호출할때):

- In a meeting(회의시간):

- Training(교육):

- Tea break(커피 타임):

- Before noon on weekend(주말 오전):

- Ready for getting off work(퇴근준비):

- Tomorrow is a holiday(내일은 휴일):

- Got today's target from boss(상사의 타겟이 된 오늘):

- Tough target(제대로 타켓이됨):

- Find impossible to meet boss's requirement(상사가 무리한 요구를 할때) :

- OT for 2hrs(연장근무 2시간):

- OT for a whole night(밤새도록 연장근무):

- Being notified to OT on weekends(주말근무까지 하게 됐을 때):

- Meet with 'Sorry-I-Don't-Know'clients(무식한 고객을 상대할 때):

- Made mistakes in work(일에서 실수할때):

- Little achievement(작은 성과를 냈을때):

- Frustrating things happens(당황스런 일이 발생했을때):

- Finance person doesn't give the money(재무 담당자가 돈을 주지 않을때):

- Being advised NO BONUS this year(보너스가 없다는 공지를 받을때):

The Offspring - You're Gonna Go Far, Kid
스트레스가 확~~
Unix Tail implementation with Java
1. 구현 소스
package client;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
public class Tail
{
public static void main(String[] args) throws IOException
{
BufferedReader input = null;
Reader fileReader = null;
if (args != null && args.length > 0) {
fileReader = new FileReader(args[0]);
input = new BufferedReader(fileReader);
String line = null;
while (true) {
if ((line = input.readLine()) != null) {
System.out.println(line);
continue;
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
} else {
System.out.println("입력 값을 확인 해 주세요.");
}
try {
if (input != null)
input.close();
if (fileReader != null)
fileReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
2. 실행 결과
Javascript기반의 Pagination
- 다운 로드 : http://plugins.jquery.com/project/pagination
- 사용 소스
<script type="text/javascript">
function pageselectCallback(page_id, jq){
$('#Searchresult').text("Showing search results "
+((page_id*10)+1)+"-"+((page_id*10)+10));
}
$(document).ready(function(){ // Create pagination element
$("#Pagination").pagination(300, {
num_edge_entries: 2,
num_display_entries: 8,
callback: pageselectCallback
});
// Set handler for setting pagination options via form
$("#setoptions").click(function(){
var opt = {callback: pageselectCallback};
$("input[@type=text]").each(function(){
opt[this.name] = this.className.match
(/numeric/)?parseInt(this.value):this.value;
});
// extract maxitems
var maxitems = opt.maxitems;
delete opt.maxitems;
// Avoid html injections in this demo
var htmlspecialchars =
{ "&":"&", "<":"<", ">":">", '"':"""}
$.each(htmlspecialchars, function(k,v){
opt.prev_text = opt.prev_text.replace(k,v);
opt.next_text = opt.next_text.replace(k,v);
})
$("#Pagination").pagination(maxitems, opt);
});
});
</script>
- 데모 : http://www.mimul.com/examples/pagenation/demo.htm
2. 일반 Javascript에서 사용
- 사용 소스
function Pager(tableName, itemsPerPage) {
this.tableName = tableName;
this.itemsPerPage = itemsPerPage;
this.currentPage = 1;
this.pages = 0;
this.inited = false;
this.showRecords = function(from, to) {
var rows = document.getElementById(tableName).rows;
// i starts from 1 to skip table header row
for (var i = 1; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}
}
this.showPage = function(pageNumber) {
if (! this.inited) {
alert("not inited");
function Pager(tableName, itemsPerPage) {
this.tableName = tableName;
this.itemsPerPage = itemsPerPage;
this.currentPage = 1;
this.pages = 0;
this.inited = false;
this.showRecords = function(from, to) {
var rows = document.getElementById(tableName).rows;
// i starts from 1 to skip table header row
for (var i = 1; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}
}
this.showPage = function(pageNumber) {
if (! this.inited) {
alert("not inited");
return;
}
var oldPageAnchor = document.getElementById('pg'+
this.currentPage);
oldPageAnchor.className = 'pg-normal';
this.currentPage = pageNumber;
var newPageAnchor = document.getElementById('pg'+
this.currentPage);
newPageAnchor.className = 'pg-selected';
var from = (pageNumber - 1) * itemsPerPage + 1;
var to = from + itemsPerPage - 1;
this.showRecords(from, to);
}
this.prev = function() {
if (this.currentPage > 1)
this.showPage(this.currentPage - 1);
}
this.next = function() {
if (this.currentPage < this.pages) {
this.showPage(this.currentPage + 1);
}
}
this.init = function() {
var rows = document.getElementById(tableName).rows;
var records = (rows.length - 1);
this.pages = Math.ceil(records / itemsPerPage);
this.inited = true;
}
this.showPageNav = function(pagerName, positionId) {
&nb







