본문 바로가기

Programming

각종 알고리즘 링크 분수(1/x)의 그래프http://www.mathteacher.pe.kr/study/21_0416.htm kadane 알고리즘http://rerun.me/2012/08/29/find-continuous-subarray-with-maximum-sum-problem-kadane-s-algorithm/ LCA (가장 가까운 공통 조상 찾아내기 - 트리에서)https://www.acmicpc.net/board/view/332 -> 댓글http://dyngina.tistory.com/29 -> 본문https://www.topcoder.com/community/data-science/data-science-tutorials/range-minimum-query-and-lowest-common-ancestor/#Low.. 더보기
Tree 이진 인덱스 트리(binary indexed tree)http://blog.secmem.org/486 인덱스 트리http://blog.naver.com/PostView.nhn?blogId=choyi0521&logNo=80204274208 더보기
이차원 배열(포인터) 활용 int arr[3][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };int (*bbb)[3] = arr+1;printf("%d\n", bbb[0][0]); 출력 4 이중 배열의 주소를 1중 배열로 받아서 쓰기 #define MAX128int g_arr[MAX * 2][MAX];int(*g_arr_128)[MAX] = g_arr;int(*g_arr_64)[MAX] = g_arr + 128;int(*g_arr_32)[MAX] = g_arr + 128 + 64;int(*g_arr_16)[MAX] = g_arr + 128 + 64 + 32;int(*g_arr_8)[MAX] = g_arr + 128 + 64 + 32 + 16;int(*g_arr_4)[MAX] = g_arr + .. 더보기
root 계산 함수 만들기 원문 : http://blog.daum.net/_blog/BlogTypeView.do?blogid=0Xrxs&articleno=41 #include double SQRT(double, double);void main() { double input, x, result; while(1) { scanf("%lf", &input); scanf("%lf", &x); result = SQRT(input, x); printf("제곱근은? : %lf \n", result); } } double SQRT(double input, double x) { for(int i=0; i 더보기
화면 출력을 버퍼로 변경하기 원문 : http://kin.naver.com/qna/detail.nhn?d1id=1&dirId=1040101&docId=243592745&qb=c2V0YnVmKHN0ZG91dCwgTlVMTCk7&enc=utf8&section=kin&rank=1&search_sort=0&spq=0 setbuf는 http://www.cplusplus.com/reference/cstdio/setbuf/에 잘나와있네요파일 스트림을 버퍼로 리다이렉션하는 함수입니다.다음 예제에서setbuf(stdout,but);히면 그이후부터 printf의 결과는 화면으로 가지않고 버퍼(buf)에 가게 됩니다.setbuf(stdout,NULL);하면 설정한 버퍼를 해제하는 것으로 이후의 printf의 결과는 화면으로 출력되게 됩니다. 더보기
빠르게 랜덤변수 발생시키기 int g_seed;int fastrand() { g_seed = (214013 * g_seed + 2531011);return (g_seed >> 16) & 0x7FFF;} 기존에는 아래와 같은 방식으로 랜덤 변수를 생성하였었다.time_t seconds;time(&seconds);srand((unsigned int)seconds);//srand((unsigned)time(0));v0 = rand() % 10; 하지만 이 방식은 초당으로 seed 가 변해서 그런지, 랜덤숫자가 빠르게 변하지 않는 단점이 있다. 이 대신에 fastrand 를 사용하면, 빠른 속도로 랜덤한 변수를 얻을 수 있다. 더보기
최소공배수, 최대공약수 - 유클리드 호제법 최대공약수 : gcd(a,b)최소공배수 : lcm(a,b) = a*b/gcd(a,b)최대공약수가 1인, 둘 이상의 양의 정수들은 서로소(relatively prime) a = Gx, b = Gy (단, x, y는 정수)일때... G 는 최대공약수최소공배수는 a*b/G 임 ---------------------- gcd(a,b) 구하기 설명 1071과 1029의 최대공약수를 구하면, 1071은 1029로 나누어 떨어지지 않기 때문에, 1071을 1029로 나눈 나머지를 구한다. => 421029는 42로 나누어 떨어지지 않기 때문에, 1029를 42로 나눈 나머지를 구한다. => 2142는 21로 나누어 떨어진다.따라서, 최대공약수는 21이다. 78696과 19332의 최대공약수를 구하면, 78696 = .. 더보기
kill parent and child process sametime #include //#include #include #include #include #include #include int main(int argc, char *argv[]){// signal(SIGALRM, timer_handler); // add handler about sigalrm pid_t pid, child_pid; int rc=0; pid = fork(); if (pid == 0){ // childprintf("[child] I'm child(%d)\n", getpid()); //char *argvs[] = {~~~~~~~, (char *)0}; //return execv(~~~~~~~~~); // run other program pid_t ppid = getppid();pid_t pgid .. 더보기
Android low memory killer disable 하기 출처 : http://varun-anand.com/mem_mgmt.htmlDISABLING ANDROID MEMORY MANAGEMENT SYSTEMLow memory killer was added as a kernel extension to the Android. The main source code is located at "/drivers/staging/android/lowmemorykiller.c". One of the interesting things to observe is the directory "staging" where the source code resides. Google added some of the kernel extensions such as wakelocks, lowmemk.. 더보기
stdout 출력을 file 로 돌리기 static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; intmain(int argc, char **argv) { time_t start = time(NULL); redirect_stdio(TEMPORARY_LOG_FILE); 더보기
xming 관련 tip 들 Xming 글씨 크기가 작을때http://blueedu.dothome.co.kr/xe/usefulinfo/21962 Xming 윈도우 창이 크기조절이 안되고 윈도우 단축키(win + 방향키)로 동작하게 하고 싶을때- 터미널 창에서 "gnome-wm &" 입력 후 이후에 linux 프로그램 실행함.=> 이 방법으로 실행하면 다른 program(gedit, meld) 등이 정상 동작까지 시간이 오래걸리는 side-effect 가 발생함.- "C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow -screen 0 1920x1080@1=> 위 옵션 추가해서 해결 더보기
Android.mk file 의 define Hierarchy 기본적으로 Android.mk 는 하위 폴더에 있는 Android.mk 와 define 이 상속되거나 공유되지 않음 - A - Android.mk- B - Andorid.mk A 폴더와 B 폴더 아래에 Android.mk 가 있다고 해도 내부에서 선언한 -D flag 는 각각 적용됨 만약 전역적으로 -D 를 적용하고 싶다면 Core.mk 에 선엄. 더보기
linux 개발을 위한 source insight tab 설정하기 원문 : http://jaram.tistory.com/202 alt + t를 누름1. Tab width를 4 로 설정2. Expand tab을 enable로 설정3. Auto Indent는 취향에 맡게 simple에 체크 둘다 해주는거... tab --> space로 일괄 변경1. 소스 전체 선택2. alt+ e3. special --> tab --> space 누름 정해진 tab width만큼으로 모두 변경됨 내가 쓰는 simple 한 치환 방법 tab 을 복사한 후Ctrl+h 를 눌러서 치환 문자열에 복사한 tab 을 붙여넣기 하고대체 문자열에 스페이스 4번 입력후 all 더보기
printf / printk 에서 %p 사용방법 %p : 주로 변수가 가지고 있는 주소값을 출력하는데 사용함. - 변수가 저장된 주소값을 출력해주는 것이 아니라, 변수가 저장하고 있는 주소값을 출력해줌- 16진수 address 로 출력해줌.- 앞에 0x 를 붙이지 않아도 알아서 출력해줌.- 주소값을 가지고 있는 void* , char* 등은 그대로 출력unsigned char* data;printf("data(%p)\n" data);- 배열은 앞에 '&'를 붙여야 함.printf("%s() psrc[d]=%p, psrc[t]=%p\n", __func__, &psrc[d], &psrc[t]); 추가하고 싶은 내용%x 와 %p 의 출력 차이점. 더보기
C 드라이브 공간확보하기 최대 절전모드 off 해서 공간 확보하기 http://hphphp.co.kr/220484530990win7을 쓰는 나의 경우 무려 8G의 용량이 새로 생겼다. 컴퓨터 -> 속성 -> 등급 -> 디스크 정리 -> c 드라이브 선택 -> 박스전원다 선택 -> 확인(이방법은 ssd 에서는 사용 안하는게 좋지않을까 싶다.) 컴퓨터 -> 속성 -> 등급 -> 디스크 정리 -> c 드라이브 선택 -> 기타 -> 시스템 복원 및 쉐도우 복사본 정리 더보기
TEMP_FAILURE_RETRY 이따금 Android code 에서 TEMP_FAILURE_RETRY mecro 를 사용한 function 들을 볼 수 있다.하지만, 이 매크로는 매우 위험할 수 있다.return true 가 발생하지 않는다면, 호출한 thread 는 영원히 loop 속으로 빠질 수 있다. 따라서 이 mecro 가 포함된 function 을 호출할때는 주의하는것이 좋다. 28#ifndef TEMP_FAILURE_RETRY 29/* Used to retry syscalls that can return EINTR. */ 30#define TEMP_FAILURE_RETRY(exp) ({ \ 31 typeof (exp) _rc; \ 32 do { \ 33 _rc = (exp); \ 34 } while (_rc == -1 && .. 더보기
터미널의 컬러 text 를 클립보드로 복사하기 아직 작성중... http://www.linuxquestions.org/questions/linux-desktop-74/preserve-colors-when-copy-pasting-from-terminal-943213/ -> perl 로 html 로 변환하는 해법http://stackoverflow.com/questions/245121/a-library-to-convert-ansi-escapes-terminal-formatting-color-codes-to-html http://stackoverflow.com/questions/5505515/how-do-i-embed-source-code-or-html-in-open-office-org-presentations-without-usin 더보기
ubuntu firefox 실행시 warning 해결 firefox 실행시 아래와 같은 warning 이 발생하면서 실행이 매우 느린 현상이 발생하였다. An error occurred while loading or saving configuration information for firefox. Some of your configuration settings may not work properly. 이 문제는 .debus 의 실행권한이 없어서 발생하는 이슈로써 다음과 같이 해결이 가능하다. https://bbs.archlinux.org/viewtopic.php?id=90671 I think I may have found a solution, can you print the output of ls -la ~/ | grep .dbusapparently thi.. 더보기
[linux] openat / open 의 차이점 출처 : http://pinocc.tistory.com/140 [linux] openat / open 의 차이점 지금은 확실히 개념이 들어오진 않는다.일단 스크랩 후 좀 더 자새히... open SYNOPSIS #include #include #include int open(const char *pathname, int flags); int open(const char *pathname, int flags, mode_t mode); int creat(const char *pathname, mode_t mode); openatSYNOPSIS #include int openat(int dirfd, const char *pathname, int flags); int openat(int dirfd, const .. 더보기
Android init.rc 분석 기본 문법http://www.dreamy.pe.kr/zbxe/CodeClip/164851 설명http://egloos.zum.com/shadowxx/v/10770478http://blog.naver.com/PostView.nhn?blogId=multiedit&logNo=40147752143 예제http://forum.falinux.com/zbxe/index.php?mid=android&sort_index=readed_count&order_type=asc&document_srl=781528 class name 을 등록하고 아래와 같이 class 를 start stop 시킬 수 있다.즉, class_start 를 호출하면 해당 class name 을 등록한 모든 service 들이 시작된다.. 더보기
fstab & partition images type 의 emmc -> 는 row data 를 뜻함.즉, filesystem 없이 blk 단위로 read/write 하는 partition 임. # /dev/block/platform/msm_sdcc.1/by-name/boot /boot emmc default recoveryonly/dev/block/platform/msm_sdcc.1/by-name/recovery /recovery emmc default recoveryonly/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 default recoveryonly/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 default wait,leng.. 더보기
linux command : stat, fstat, lstat http://s2kiess.blog.me/220139796462 stat : 파일경로를 가지고 파일 속성을 가지고 온다.fstat : 파일 디스크립터를 가지고 파일 속성을 가지고 온다. 심볼릭 링크의 경우 원본 파일의 속성을 가지고 온다.lstat : fstat 과 동일하나, 심볼링 링크일 경우 링크 파일의 속성을 가지고 온다. The usage of "stat" on arm linux # statusage: stat [-f] [-c FORMAT] FILE... Display status of files or filesystems. -f display filesystem status instead of file status-c Output specified FORMAT string instead of d.. 더보기
헷갈리는 c string 함수들 정리중... strstr은 문자열 중에서 특정 문구를 찾아 그 위치를 반환해 주는 함수특히, 포함된 문자열을 찾는데 유용하다. (strcmp 를 사용하면 안된다 !!) /*strstr */char * strstr(const char * str1, const char * str2); 참조 : http://tapito.tistory.com/313 1. strcat - strcat (string concatenation)은 문자열 2개를 이어 붙이는 역할을 해주는 함수이다. 예컨대, "Love"와 "You"를 합치면 LoveYou가 될 것이다. 이처럼 두개의 문자열을 합쳐주는 함수가 strcat 이다. 이 함수의 사용방법과 내부적인 결과를 자세히 살펴보자. 먼저 함수의 모양을 알아보자. 함수.. 더보기
epoll 에 대한 한국어 설명 poll 이나 select 의 비 효율성을 해결한 새로운 기능. http://vovheas104.blog.me/220485326114 http://cafe.naver.com/newchany/87 더보기
close_on_exec static __inline__ int adb_socketpair( int sv[2] ){ int rc; rc = unix_socketpair( AF_UNIX, SOCK_STREAM, 0, sv ); if (rc < 0) return -1; close_on_exec( sv[0] ); close_on_exec( sv[1] ); return 0;} static __inline__ void close_on_exec(int fd){ fcntl( fd, F_SETFD, FD_CLOEXEC );} #include int execve(const char *filename, char *const argv[], char *const envp[]);함수를 호출하면 기본적으로는 file descriptor 가 open 된 .. 더보기
socketpair() 출처 : http://osr507doc.sco.com/en/netguide/dusockD.socketpairs_codetext.html socketpair: read / write 가 가능한 한쌍의 socket 을 open 한다. 예제 Socketpair sample code (UNIX only)The following example illustrates the use of socketpairs, which are a slight generalization of pipes used for two-way stream communication. Because socketpairs are an extension of pipes, their use resembles that of pipes rather than.. 더보기
linux signals 출처 : http://fehead.tistory.com/146 SIGPIPE파이프가 끊겼을 경우 발생하는 signalhttp://blog.naver.com/PostView.nhn?blogId=hyungii&logNo=130081645365 * 파이프깨짐?소켓은 프로세스간 통신 메카니즘의 확장으로 볼 수 있습니다.전형적인 유닉스의 프로세스간통신(IPC라고 하지요) 메카니즘은 파이프입니다.이러한 관습(?)에 힘입어, 소켓에서도 그 연결이 끊기는 경우 파이프가 끊겼다느니, 깨졌다느니, broken pipe등의 메시지를 사용합니다.파이프깨짐은 바로 통신의 종결을 의미합니다. 통신이 끊김은 어떻게 감지하는가? 보통 3가지 방법이 있을 수 있습니다.1) 상태검사 : 소켓도 파일로 간주하므로, 파일의 상태정보를 읽어.. 더보기
linux stand out 을 file 에 logging 하기 static const char *TEMPORARY_LOG_FILE = "/tmp/recovery.log"; redirect_stdio(TEMPORARY_LOG_FILE); static void redirect_stdio(const char* filename) { // If these fail, there's not really anywhere to complain... freopen(filename, "a", stdout); setbuf(stdout, NULL); freopen(filename, "a", stderr); setbuf(stderr, NULL);} 더보기
linux namespace 각각의 process 가 가지고 있는 mount set다른 FS namespace 를 가지고 있는 process 는 서로 다른 mount information 을 가지고 있다.각 process 의 proc 의 ns 에서 FS namespace 를 확인 할 수 있다. root@klte:/proc/7532 # ls -al /proc/7939/ns lrwxrwxrwx bluetooth bluetooth 2015-01-02 11:09 mnt -> mnt:[4026534520]lrwxrwxrwx bluetooth bluetooth 2015-01-02 11:09 net -> net:[4026533490]root@klte:/proc/7532 # ls -al /proc/7532/nslrw.. 더보기
sudo -s / su 와의 차이점 sudo -s 계정은 그대로 user 계정인 상태에서 이후 실행되는 명령어 들만 root 권한으로 실행시킴 su계정이 root 로 변경됨 su 와 su - root(su -) 와의 차이점이 아래 설명되어 있지만 맞는지는 모르겠음.http://blog.naver.com/ooobba/70189243851 더보기