rm -rf 대신 사용

배운 것 2016. 4. 5. 11:43

find . -name "A*log.*" -mtime +31 -exec ls -alh {} \;

find . -name "A*log.*" -mtime +31 -exec rm {} \;


'배운 것' 카테고리의 다른 글

utf-7 vs utf-8  (0) 2016.04.03
base64 vs base64url safe 차이  (2) 2016.04.03
perl로 날짜 비교 하기  (0) 2016.03.28
holder pattern in java  (0) 2016.03.15
[linux command ] which, whereis  (0) 2016.03.04
Posted by 썬,더 호글
,

utf-7 vs utf-8

배운 것 2016. 4. 3. 21:12

https://en.wikipedia.org/wiki/UTF-7


It was originally intended to provide a means of encoding Unicode text for use in Internet E-mail messages that was more efficient than the combination of UTF-8 with quoted-printable.


일단은 이렇게 이해해놓으면 좋겠다. email 도메인 특성 상 고안되어 사용된 것으로 보인다. 

'배운 것' 카테고리의 다른 글

rm -rf 대신 사용  (0) 2016.04.05
base64 vs base64url safe 차이  (2) 2016.04.03
perl로 날짜 비교 하기  (0) 2016.03.28
holder pattern in java  (0) 2016.03.15
[linux command ] which, whereis  (0) 2016.03.04
Posted by 썬,더 호글
,

컴퓨터 분야에서 쓰이는 Base 64 (베이스 육십사)란 8비트 이진 데이터(예를 들어 실행 파일이나, ZIP 파일 등)를 문자 코드에 영향을 받지 않는 공통 ASCII 영역의 문자들로만 이루어진 일련의 문자열로 바꾸는 인코딩 방식을 가리키는 개념이다.


문장이 끝나면 '=' 로 데이터가 끝났다는 것을 표시한다. 다시 데이터를 원복할 때 틀리지 않도록 방지하기 위함이다. 문장 하나를 Base64 에 의거해서 데이터를 변경하는 방법은 아래와 같다. 



1. 캐릭터 하나를 아스키 문자에 대응한다. 

2. 해당하는 아스키 문자를 8비트 패턴으로 변경한다. 

3. 8비트를 앞에서부터 6비트 씩 잘라서 다시 십진수로 변경한다. 

4. 그 값으로 나온 십진수를 Base64의 색인표에 대응시켜 나온 값으로 대응한다. 

5. 이 작업을 반복한다. 


* 출처: 위키 백과 참조 (https://ko.wikipedia.org/wiki/베이스64) 

----


url safe한 base64 란. 어렵지 않아요~


표1 base 64 original 



62, 63을 보면 각각 +, / 에 대응되는 것을 알 수 있다. 그러나 이는 데이터를 컨트롤할 때 오류를 일으킬 수 있는 문제가 될 수도 있고 = 가 url에서 사용하는 문자라는 문제 등이 제기 되었다. 따라서 아래와 같이 변경해버렸다. 아래의 url safe 한 base64 의 62, 63번은 - , _로 대체되었다. 




참조: https://tools.ietf.org/html/rfc4648


5. Base 64 Encoding with URL and Filename Safe Alphabet

The Base 64 encoding with an URL and filename safe alphabet has been used in [12]. An alternative alphabet has been suggested that would use "~" as the 63rd character. Since the "~" character has special meaning in some file system environments, the encoding described in this section is recommended instead. The remaining unreserved URI character is ".", but some file system environments do not permit multiple "." in a filename, thus making the "." character unattractive as well. The pad character "=" is typically percent-encoded when used in an URI [9], but if the data length is known implicitly, this can be avoided by skipping the padding; see section 3.2. This encoding may be referred to as "base64url". This encoding should not be regarded as the same as the "base64" encoding and should not be referred to as only "base64". Unless clarified otherwise, "base64" refers to the base 64 in the previous section. This encoding is technically identical to the previous one, except 

   for the 62:nd and 63:rd alphabet character, as indicated in Table 2.


'배운 것' 카테고리의 다른 글

rm -rf 대신 사용  (0) 2016.04.05
utf-7 vs utf-8  (0) 2016.04.03
perl로 날짜 비교 하기  (0) 2016.03.28
holder pattern in java  (0) 2016.03.15
[linux command ] which, whereis  (0) 2016.03.04
Posted by 썬,더 호글
,

1. epoch로 초를 계산해서 30일을 초로 변환해서 뺀 다음에 그 값을 비교 

2. str2+time 을 이용해서 스트링을 epoch로 바꿔서 계산. 스트링을 변환하는 작업을 대신해주는 셈.

3. localtime을 이용해서 epoch로 초단위 계산. 


> 결국 초단위 계산을 통해서 스트링을 날짜 계산하게 된다. 

'배운 것' 카테고리의 다른 글

utf-7 vs utf-8  (0) 2016.04.03
base64 vs base64url safe 차이  (2) 2016.04.03
holder pattern in java  (0) 2016.03.15
[linux command ] which, whereis  (0) 2016.03.04
[linux command] mkdir -p -m  (0) 2016.03.04
Posted by 썬,더 호글
,

holder pattern in java

배운 것 2016. 3. 15. 18:01

홀더 패턴이라는 것을 처음 이용해보았다. 거의 받아쓰기 하듯이 짝코딩을 했는데, 하고 나서 찬찬히 보고 문서를 살펴보니 좀 이해할 수 있게 되었다. 그리고 이건 좋지 않다. 키보드를 치면 화면이 너무 많이 흔들린다. 


홀더 패턴이라고 검색하면 잘 나오지 않고, Initialization on demand holder idion이라고 정의되어 있는 것 같다. 


간단히 훑어봤을 때 장점은 lazy loading이다. 형식은 아래 문서들을 참고하면 쉽게 이해할 수 있다. A클래스에 대한 getInstance()함수를 수행하면 A클래스의 싱글톤 객체를 리턴한다. 그렇지만 내부를 살펴보면 A클래스의 Inner class인 B클래스의 필드를 리턴하는 것으로부터 A클래스의 싱글톤 객체를 가져다 쓸 수 있게 되는 것이다. 




정리하자면 


public class A {

public A getInstance (){ return B._instance();}

private static class B{

private A _instance = new A();

}

}



- 검색해서 이해하기 좋았던 문서 2개 

1. http://gampol.tistory.com/entry/Double-checked-locking%EA%B3%BC-Singleton-%ED%8C%A8%ED%84%B4

2. https://en.wikipedia.org/wiki/Initialization-on-demand_holder_idiom



'배운 것' 카테고리의 다른 글

base64 vs base64url safe 차이  (2) 2016.04.03
perl로 날짜 비교 하기  (0) 2016.03.28
[linux command ] which, whereis  (0) 2016.03.04
[linux command] mkdir -p -m  (0) 2016.03.04
[linux command] cut  (0) 2016.03.04
Posted by 썬,더 호글
,

명령어의 위치를 알고 싶다면 which를 사용할 수 있다. 

단점은 path에서 처음 발견된 which에 관한 위치만 나온다는 점이다. 

이를 보완하고 싶을 경우 -a 옵션을 주면 해당하는 모든 위치가 나온다. 


~/test/shPractice which grep

grep: aliased to grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}

~/test/shPractice which -a grep

grep: aliased to grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}

/usr/bin/grep


 whereis는  명령어의 실행파일위치, 소스위치, man 페이지파일의 위치를 찾아주는 명령어라고 한다. (출처: http://webdir.tistory.com/158)



'배운 것' 카테고리의 다른 글

perl로 날짜 비교 하기  (0) 2016.03.28
holder pattern in java  (0) 2016.03.15
[linux command] mkdir -p -m  (0) 2016.03.04
[linux command] cut  (0) 2016.03.04
git 명령어 alias 를 이용해서 짧게 쓰기  (0) 2016.03.03
Posted by 썬,더 호글
,

~/test/shPractice mkdir -p ./test/test2/test3


~/test/shPractice cd test/test2/test3/



-p 옵션은 parent 옵션.mkdir 을 할 때 실제로 존재하지 않는 디렉토리가 확인될 경우 생성해준다. 


~/test/shPractice mkdir -m 755 /test/testtest/testtesttest   


-m 옵션은 보호 모드를 설정해서 디렉토리를 순차적으로 생성해준다. 




'배운 것' 카테고리의 다른 글

holder pattern in java  (0) 2016.03.15
[linux command ] which, whereis  (0) 2016.03.04
[linux command] cut  (0) 2016.03.04
git 명령어 alias 를 이용해서 짧게 쓰기  (0) 2016.03.03
byte[] 를 String으로 읽어들일 때  (0) 2016.02.01
Posted by 썬,더 호글
,

[linux command] cut

배운 것 2016. 3. 4. 21:59

cut -d /; -f 3,4 text.log


cut 명령어에서 


- d, --delimeter와 같아. 뒤에 나오는 캐릭터로 문자열을 배열 형태로 파싱한다. 

- 위의 예시에서 세미콜론 앞에 역슬래쉬가 붙어있는 이유는 파싱 기준이 세미콜론이라서. (명령어 종료로 인식)

- -f 는  cut -d의 결과로 나온 배열의 field를 의미. -f 3 하면 3번째 필드가, -f 3,4 하면 3번째, 4번째 필드가 출력된다. 

- 단, 이 필드의 순번은 0 이 아니라 1번부터 시작한다. 싱-기-




+덧붙임


7117  cat error_json_2016-06-08.log|cut -d ;     (실패)

 7118  cat error_json_2016-06-08.log|cut -d;    (실패)

 7119  cat error_json_2016-06-08.log|cut -d\;    (실패)

usage: cut -b list [-n] [file ...]

       cut -c list [file ...]

       cut -f list [-s] [-d delim] [file ...]


 7120 cat error_json_2016-06-08.log|cut -d'\;' (실패)

 7127  cat error_json_2016-06-08.log|cut -d: -f1 (성공) -- -d랑 -f를 같이 써야되는군!



 7197  cat 1139_json.log|cut -d ';'    (실패)

 7198  cat 1139_json.log|cut -d '='    (실패)

 7199  cut 1139_json.log -d '='    (실패)

 7201  cat 1139_json.log |cut -d =    (실패)

 7202  cat 1139_json.log |cut -d=    (실패)

 7203  cat 1139_json.log |cut -f -d=     (실패)

 7203  cat 1139_json.log |cut -f1 -d=    (성공)

 7204  cat 1139_json.log |cut -cf -d=    (실패)

cut: [-cf] list: illegal list value


 7205  cat 1139_json.log |cut -cf    (실패)

 7207  cat 1139_json.log |cut -d '=' -f 2     (실패)



Posted by 썬,더 호글
,

주로 git을 터미널로 쓰기를 즐겨 하는 나는 일단 깃 폴더에 들어가는 순간 습관적으로 git status를 친다. (물론 터미널 접속해서는 ls를 친다.) 그런데 git add 한번하고 나서 매번 git status를 치는 것보다는 기왕이면 짧게 쓰는게 좋았을텐데 그걸 이제야 눈동냥;으로 알게 되었다. 


git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
git config --global alias.hist 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'
git config --global alias.type 'cat-file -t' 

git config --global alias.dump 'cat-file -p'


물론 alias로 전역에 등록해서 더 짧게 사용하는 방법도 있겠지만, git config에이걸 등록해놓을 수도 있다는 것이다. 처음 알았네. alias가 복잡해지는 거....그래, 사실 나는 alias를 등록해서 쓴지 5개월 정도 밖에 안됐다. 모르면 배우면 되지 뭘-_-


정보 출처: alias 등록하는 법도 잘 나와있다. 

https://githowto.com/aliases

'배운 것' 카테고리의 다른 글

[linux command] mkdir -p -m  (0) 2016.03.04
[linux command] cut  (0) 2016.03.04
byte[] 를 String으로 읽어들일 때  (0) 2016.02.01
사소하지만 중요한 리팩토링  (0) 2016.01.28
command pattern  (0) 2016.01.28
Posted by 썬,더 호글
,
protected String getMessageBody(Message message) {
        // String messageBody = new String(message.getBody());
        // charset 이 지정 안되어 버그 가능성이 있는 코드.
        // getBody() 의 return type 이 무엇이냐에 따라 다르지만, 만약 byte[] 형태이고 내용이 json 형식이라면 아래처럼 권장
        return new String(message.getBody(), StandardCharsets.UTF_8);
    }



byte[] 를  String으로 읽어들이고 싶을 때, charset이 설정되지 않으면 버그 가능성이 있다고 한다. -by dex.

'배운 것' 카테고리의 다른 글

[linux command] cut  (0) 2016.03.04
git 명령어 alias 를 이용해서 짧게 쓰기  (0) 2016.03.03
사소하지만 중요한 리팩토링  (0) 2016.01.28
command pattern  (0) 2016.01.28
log4j error  (0) 2016.01.26
Posted by 썬,더 호글
,