manywaypark's Blog
개발, 검색, 함수

가끔은 자기 자신이 어디서 로딩되었는지를 알아야만 할 때가 있다.

static initialization 과정에서 함수의 주소로 알아내는 방법이 있다.

#define _GNU_SOURCE

#include <dlfcn.h>

#include <stdio.h>


__attribute__((constructor))

void on_load(void) {

  Dl_info dl_info;

  dladdr((void *)on_load, &dl_info);

  fprintf(stderr, "module %s loaded\n", dl_info.dli_fname);

}

좀더 자세한건 man 3 dladdr


refs: 

http://stackoverflow.com/questions/1681060/library-path-when-dynamically-loaded

https://cseweb.ucsd.edu/~gbournou/CSE131/the_inside_story_on_shared_libraries_and_dynamic_loading.pdf

the_inside_story_on_shared_libraries_and_dynamic_loading.pdf

happy hackin'

Qt에서 pkg-config 쓰기

tips & tricks/Qt 2017. 3. 28. 23:42 by manywaypark


보통 아래처럼 패키지 정보를 조회후에 결과 스트링을 Makefile이나 build script의 CFLAGS나 CXXFLAGS, LDFLAGS등에 추가해서 쓰는데...


$ pkg-config --cflags protobuf

-pthread -I/usr/local/include

$ pkg-config --libs protobuf

-L/usr/local/lib -lprotobuf -pthread -lpthread


Qt의 qmake에서는 프로젝트 파일에 아래처럼 써주면 똑같은 효과를 낼 수 있다.


CONFIG += link_pkgconfig

PKGCONFIG += protobuf


ref: http://stackoverflow.com/questions/3517694/linking-libraries-to-a-qt-project-using-pkg-config-output


happy hackin'

gitignore

tips & tricks 2017. 3. 22. 20:56 by manywaypark

git을 사용할 때 .gitignore 파일을 제대로 만들어놓지 않으면 git repository가 지저분해진다.

REST API를 통해 간단히 만들 수 있는 방법이 있다고 알려주는 페이지가 있는데, 오늘(2017-03-22) 기준으로 응답이 제대로 오지 않았다.

https://www.lesstif.com/pages/viewpage.action?pageId=18220154

직접 접속해서 해보니 되는데, 위의 링크에서 http를 https로만 바꾸면 제대로 동작한다.

직접 여기(https://github.com/joeblau/gitignore.io)를 보았으면 한번에 잘되었겠다.

물론 전통의 https://github.com/github/gitignore 를 보는 것이 더 좋을 수도 있겠다.


간단히 mac과 linux에서의 global gitignore 설정을 해보자 (bash 환경기준. 다른 환경은 상기 링크 참조)

mac:

$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bash_profile && source ~/.bash_profile

$ gi osx,emacs > ~/.gitignore_global

$ git config --global core.excludesfile ~/.gitignore_global


linux:

$ echo "function gi() { curl -L -s https://www.gitignore.io/api/\$@ ;}" >> ~/.bashrc && source ~/.bashrc

$ gi linux,emacs > ~/.gitignore_global 

$ git config --global core.excludesfile ~/.gitignore_global

gi list를 하면 모든 지원되는 항목을 볼 수 있다.


happy hackin'

Mac에서 스크린샷 찍기

tips & tricks/Mac 2017. 3. 22. 14:07 by manywaypark

링크에 잘 설명 되어 있다.

요점은 shift + command + (control) + 3 or 4


https://support.apple.com/ko-kr/HT201361

http://www.wikihow.com/Take-a-Screenshot-in-Mac-OS-X


happy hackin'

초간단 emacs package 관리법

emacs 2017. 3. 21. 15:57 by manywaypark

아래 페이지를 방문해서 설치방법을 참고하여 emacs.d를 설치한다.

https://github.com/purcell/emacs.d

이제 emacs를 다시 시작하면 개발자에게 필요한 대부분의 패키지들이 깔려있다. 


가끔 아래 세가지 명령으로 패키지 업데이트를 해준다.

M-x package-refresh-contents

M-x package-list-packages

Ux


아주 가끔 불필요한 패키지를 아래 명령으로 지워준다.

M-x package-autoremove


happy hackin'

Erlang NIF 최적화

함수형 언어/Erlang 2017. 3. 20. 10:30 by manywaypark

첨부 문서(원본 소실에 대비해 첨부)는 오래 걸리는 nif function call에 관해 심도있게 고찰한 문서이다.


간단히 요약한다.


0. 전제

NIF의 제약 사항은 아주 빨리 처리를 끝내야한다는 것이다 (보통 1~2 ms)

이유는 native code를 처리할 때는 ERTS의 scheduler가 block되므로 다종다양한, 파악조차 힘든 문제를 겪을 수 있다.

(대표적으로 여러 노드가 통신하는 상황이면 60초 timeout에 걸릴 수 있는데, 처음 경험하면 아주 난감한 상황이 될 것이다)

참고로 function call의 처리가 끝나는 시점은 return value를 받는 시점이다.


1. chunking

말 그대로 조금씩 잘라서 처리하는 것이다. 


2. enif_schedule_nif (+ enif_consume_timeslice)

chunking을 좀더 편하게 해주는 API가 추가된 것이다.


3. dirty schedulers:

task의 성격에 따라 schedule 정책을 달리하는(?) 것이다.

기본적으로 ERTS에 포함되지 않았으므로 이렇게 ERTS compile:

configure --enable-dirty-schedulers

사용:

ErlNifFunc 정의에서 ERL_NIF_DIRTY_JOB_CPU_BOUND, ERL_NIF_DIRTY_JOB_IO_BOUND 등의 flag를 준다.



4. thread 사용(어디서 읽었는데 이 문서는 아닌듯)

nif function은 caller pid 정도만 저장하고 바로 return한다.

worker thread가 오래 걸리는 작업을 처리한 후에 enif_send로 caller process에 전달한다. caller process는 receive해서 결과를 받는다.


14115736879341vinoskioptnativecode.pdf



원본: http://www.erlang-factory.com/static/upload/media/14115736879341vinoskioptnativecode.pdf


happy hackin'



VirtualBox VM export/import on CLI

tips & tricks 2017. 3. 17. 18:26 by manywaypark

가끔 GUI tool을 사용하지 못하는 상황에 처할 때가 있다.

command line에서 VirtualBox의 VM을 export/import 하는 방법은 아래와 같다.


1. 일단 VM 리스트 확인:

~$ vboxmanage list vms

"Win8.1" {e0c9a708-0be9-46b0-8f0d-80304d1d1e66}

"PXE-Srv" {4ee3b1c8-c475-4c4f-bd33-78c44e2816d2}

"test" {6f2a8a53-8093-41be-8523-772e0ee5bb52}

......


2. Win8.1을 export:

~$ vboxmanage export Win8.1 -o Win8.1.ova


3. 다른 박스로 Win8.1.ova 파일을 옮긴 후에 import:

~$ vboxmanage import Win8.1.ova


happy hackin'


Elixir 창시자의 변

함수형 언어/Elixir 2017. 2. 13. 10:23 by manywaypark

좀 오래된 글이지만 창시자의 꼬드김(?) 스크랩.

Concurrent and Distributed Programming with Erlang and Elixir: part1, part2


happy hackin'

a package manager for windows

tips & tricks/Win 2017. 2. 3. 18:13 by manywaypark

윈도우에서도 패키지 관리를 해보자.


https://chocolatey.org/


happy hackin'

problem:

python에서 matplotlib를 사용하여 그래프를 화면에 출력하려고 할때 아래와 같은 오류 메시지가 나오고 제대로 안되는 경우가 있다.


>>> import tkinter

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/home/dhpark/.asdf/installs/python/3.5.2/lib/python3.5/tkinter/__init__.py", line 35, in <module>

    import _tkinter # If this fails your Python may not be configured for Tk

ImportError: No module named '_tkinter'


__init__.py 파일에서 모듈 import에 실패한다는 것인데 해결 방법은 찾아보면 간단하다.


solution #1:

우분투의 경우 python3-tk, tk-dev 패키지 두개만 깔면 해결된다.

그러나 이 방법은 package manager를 통해서 python3를 깔았을때에만 적용되는 것으로 보인다.


solution #2:

요즘은 버전간의 자유로운 전환을 위해서 virtualenvasdf같은 유틸리티의 도움을 받는 경우가 많은데 (물론 내경우도 포함), 이 경우에는 #1의 해법이 통하지 않는다.

상기 패키지2개를 설치한 후에 python을 지우고 다시 깔아야한다.

asdfvirtualenv같이 설치과정에서 compile을 거치는 놈들은 시스템에 설치안된 것을 생략해버리는 것으로 추측된다. 정확한 원인은 좀 더 봐야겠지만 귀찮다.


happy hackin'

1 2 3 4 5 6 7 8 ··· 31 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-26 05:01