'Domain'에 해당되는 글 103건

  1. 2013.06.13 git server daemon 설치하기
  2. 2013.05.31 atime 대신에 strictatime을 사용하자!
  3. 2013.05.23 [Tip] 시간 차(delta) 측정을 위한 코드에서 사용할 수 있는 아~주~ 작은 tip - ex. JAVA
  4. 2013.03.28 [Shell] Variable Name Expansion
  5. 2012.12.08 [Android] Important point when design Fragment.
  6. 2012.12.07 [Android] One thing to keep in mind when using FragementPagerAdapter
  7. 2012.11.16 [Android - ICS] Strange behavior of Android PatternMatcher - used by pathPattern of IntentFilter
  8. 2012.10.26 [Android] Status Bar height
  9. 2012.10.23 [Android] Issue : Too slow to scroll the list which has sqlite-cursor-adapter.
  10. 2012.10.23 [Android] Way to avoid using 'notifyDataSetChanged' when only one or two items are changed at Adapter.

git server daemon 설치하기

Domain/Linux 2013.06.13 13:37

Ubuntu 12.04 64 bit LTS


* git 을 설치


* server가 실행될 때 항상 실행되도록 Upstart Script 등록

/etc/init/<script name>.conf


<참고>

xxxx.conf : upstart script

xxxx.override : 기존의 xxxx.conf를 override함.


* /etc/init/git-daemon.conf 작성 (git project directory = /work/.prjrepo/)


start on runlevel [2345]                                                                        

stop on runlevel [!2345]                                                                        


expect fork                                                                                     

respawn                                                                                         


exec /usr/bin/git daemon --user=gitro --group=gitro --reuseaddr --base-path=/work/.prjrepo/ /work/.prjrepo/


* export하고자 하는 git repository안에 magic file인 git-daemon-export-ok 파일 생성 (size 0인 dummy file - 그냥 touch로 생성하면 된다.)


* client에서 test.

git clone git://<host>/<project>

<9418 포트 사용>

신고

'Domain > Linux' 카테고리의 다른 글

[Linux] mmap and memory...  (0) 2013.10.07
CoW(Copy on Write) on ARM  (0) 2013.09.26
git server daemon 설치하기  (0) 2013.06.13
atime 대신에 strictatime을 사용하자!  (0) 2013.05.31
[Shell] Variable Name Expansion  (0) 2013.03.28
[Linux][Shell] Cleaning PATH environment variable.  (0) 2011.09.15
Trackback 0 : Comment 0

atime 대신에 strictatime을 사용하자!

Domain/Linux 2013.05.31 16:43

Ubuntu의 경우 default mount option이 'relatime'으로 되어 있는데, 이것을 바꾸기 위해서 "mount -o remount,atime,xxxx" 식으로 해도 relatime 에서 atime으로 mount상태가 바뀌지 않는다.

대신 strictatime을 사용하면, 정상적으로 원하는 형태로 mount할 수 있다.

(mount의 man page에 상세하게 설명이 나와있긴 하나... atime이상 동작하지 않는다는 설명은 찾을 수 없었다.)


요점은 atime 대신 strictatime을 사용하라!

신고
tags : Linux, mount, ubuntu
Trackback 0 : Comment 0

[Tip] 시간 차(delta) 측정을 위한 코드에서 사용할 수 있는 아~주~ 작은 tip - ex. JAVA

Domain/Software 2013.05.23 13:04

특정 코드 구간이 수행되는 시간을 측정해야 할 경우가 종종 생기는데, 대부분 아래와 같은 방법을 사용한다. (ex. Java)

 

long tm = System.currentTimeMillis();
< do something >
tm = System.currentTimeMillies() - tm;
System.out.println("Time : " + tm);
그렇지만, 약간만 응용을 하면 아~주~ 조금이지만, 위의 코드를 더 간단하게 만들 수 있다.

long tm = -System.currentTimeMillis();
< do something >
tm += System.currentTimeMillis();
System.out.println("Time : " + tm);

어떤가? ^_^

신고
Trackback 0 : Comment 0

[Shell] Variable Name Expansion

Domain/Linux 2013.03.28 16:53


Variable operator

Action 

Description 

${varname}

Nonambiguous variable substitution 

Simple variable substitution occurs with the value of varname being substituted

${varname:=value}

Assign a default value for the variable if a value does not exist.

If varname does not have a value or is set to null, then varname is set to value.

Varname is then substituted in the statement.

${varname:+value} 

Utilize value if varname is set 

If the variable, varname, contains a value and is not null, then the alternate value, value, is substituted instead of the value of the variable varname. Otherwise nothing is substituted.

${varname:-value} 

Assign a temporary default value for a variable if one does not exist 

If the variable, varname, contains a value and is not null, then it is substituted; otherwise the value, value, is substituted but is not assigned to varname. (different from = operator)

${varname:?value} 

Issue an error message if the value of variable is not set to any value. 

If the variable, varname, containsa value and is not null, then it is substituted; otherwise an error message containing the value, value, is printed and the Shell exits.

${#varname}
(Korn and Bash only) 

Return the length of the value contains in varname or the number of positional parameters.

If varname is set, the length of the value of varname is returned. If the special variable * or @ is used as varname then the number of positional parameters are returned. 

${varname#pattern}

${varname##pattern}

(Korn and Bash only) 

Substitue varname with pattern removed from the beginning of varname .

If the pattern matches the begining of varname, then pattern is removed from varname. If the # form is used, then the shortest match is removed. If the ## form is used, then the longest match is replaced. 

${varname%pattern}

${varname%%pattern}

(Korn and Bash only) 

Substitute varname with pattern removed from the end of varname. 

If the pattern matches the end of varname, then pattern is removed from varname. If the % form is used, then the shortest match is removed. If the %% form is used, then the longest match is replaced. 

${#arrayname[*]}
(Korn only) 

Substitute the number of elements in the array. 

The number of elements in the array arrayname is substituted. 


<From : UNIX Shell Programming, FOURTH EDITION, LOWELL JAY ARTHUR, TED BURNS - WILEY COMPUTER PUBLISHING>

신고
Trackback 0 : Comment 0

[Android] Important point when design Fragment.

Domain/Android 2012.12.08 16:38

Sometimes FragmentManager destroys and re-instantiates Fragment without any notification by framework's behavior.

Important point here is that default Constructor is used to re-instantiate Fragment.

In this case, without saving and restoring run-time state of Fragment, it looses all of it's state.

This is exactly same with Activity.

But, in terms of Activity, user can know and control when the Activity is destroyed and recreated.

So, in case of Activity, this issue is not big problem.


Therefore, followings should be considered to design Fragment.

- use ONLY default constructor. (FragmentManager uses only default constructor.)

- should NOT have any not-parcelable- run-time data.


But, sometimes, Fragment may need to have not-parcelable-run-time data.

In this case, using Activity can be good choice.

That is, let owner Activity have the data and access it by using getActivity() method.


신고
Trackback 0 : Comment 0

[Android] One thing to keep in mind when using FragementPagerAdapter

Domain/Android 2012.12.07 10:26
FragmentPagerAdapter is very useful and easy-to-use.
But, there is one point to keep it mind when using it.
See below codes from FragmentPagerAdapter.java

    @Override
    public Object instantiateItem(View container, int position) {
        if (mCurTransaction == null) {
            mCurTransaction = mFragmentManager.beginTransaction();
        }

        // Do we already have this fragment?
        String name = makeFragmentName(container.getId(), position);
        Fragment fragment = mFragmentManager.findFragmentByTag(name);
        if (fragment != null) {
            if (DEBUG) Log.v(TAG, "Attaching item #" + position + ": f=" + fragment);
            mCurTransaction.attach(fragment);
        } else {
            fragment = getItem(position);
            if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
            mCurTransaction.add(container.getId(), fragment,
                    makeFragmentName(container.getId(), position));
        }
        if (fragment != mCurrentPrimaryItem) {
            fragment.setMenuVisibility(false);
            fragment.setStartDeferred(true);
        }

        return fragment;
    }

Usually, FragmentPagerAdapter is used with ViewPager. In this case, variable container is reference of ViewPager.

Developer who are familiar with normal AdapterView, may try to change FragmentPagerAdapter by using setAdapter interface of ViewPager without doing something else to ViewPager.

But, in this case, as you can see from above code, instantiateItem function reuses previous Fragment instance because even if FragmentPagerAdapter is changed, ViewPager is same. So, fragment name getting from makeFragmentName function returns same value.

And that is NOT expected result at normal AdatperView.


신고
Trackback 0 : Comment 0

[Android - ICS] Strange behavior of Android PatternMatcher - used by pathPattern of IntentFilter

Domain/Android 2012.11.16 17:57

[ Android ICS ]

PatternMatcher is used for pathPattern at IntentFilter

But, PatternMatcher's algorithm is quite strange to me.

Here is algorithm of Android PatternMatcher.


If there is 'next character' of '.*' pattern in the middle of string, PatternMatcher stops loop at that point.

(See PatternMatcher.java of Android framework.)


Ex.

string  : "this is a my attachment"

pattern : ".*att.*".

Android PatternMatcher enter loop to match '.*' pattern until meet the next character of pattern

(at this example, 'a')

So, '.*' matching loop stops at index 8 - 'a' between 'is' and 'my'.

Therefore result of this match returns 'false'.


Quite strange, isn't it.

To workaround this - actually reduce possibility - developer should use annoying stupid pathPattern.


Ex.

Goal : Matching uri path which includes 'message'.

<intent-filter>

...

<data android:pathPattern=".*message.*" />

<data android:pathPattern=".*m.*message.*" />

<data android:pathPattern=".*m.*m.*message.*" />

<data android:pathPattern=".*m.*m.*m.*message.*" />

<data android:pathPattern=".*m.*m.*m.*m.*message.*" />

...

</intent-filter>


This is especially issued when matching with custom file extention.


Ex.

Goal : Matching file which extention is 'myextention'.


Below filter doesn't work as expected because of issue described above.

(Ex. "sample.test.myextention" doesn't match by PatternMatcher.)

<intent-filter>

...

<data android:pathPattern=".*\\.myextention" />

...

</intent-filter>


So, like above, stupid-dirty filter should be used as follows.

<intent-filter>

...

<data android:pathPattern=".*\\.myextention" />

<data android:pathPattern=".*\\..*\\.myextention"/>

<data android:pathPattern=".*\\..*\\..*\\.myextention"/>

<data android:pathPattern=".*\\..*\\..*\\..*\\.myextention"/>

...

</intent-filter>


Done. :-)

신고
Trackback 0 : Comment 0

[Android] Status Bar height

Domain/Android 2012.10.26 17:20

Height of status bar can be read by following way. (can be found easily by Googling - ex. stack-overflow)


Rect rect= new Rect();

Window window= activity.getWindow();

window.getDecorView().getWindowVisibleDisplayFrame(rect);

return rect.top;


But, even after hiding status bar by adding LayoutParams.FLAG_FULLSCREEN at onCreate() or onResume(), height of status bar read by above way, may be still invalid (Not 0).

(I didn't analyze deeply about WindowManager. So, I'm not sure about root cause - due to animation effect??? or something else???)

To workaround this issue, the best place to read height of status bar - hidden or shown - is onWindowFocusedChanged().

Reading height of status bar at the first call of onWindowFocusedChanged() gives exact(expected) value based on my experience.

And then, this value can be reused afterward.


신고
Trackback 0 : Comment 0

[Android] Issue : Too slow to scroll the list which has sqlite-cursor-adapter.

Domain/Android 2012.10.23 12:03
Sometimes developer may be faced with below log message with extremely-slow-scrolling of List.


Log includes "Window is full: requested allocation 2195889 bytes, free space 2096720 bytes, window size 2097152 bytes"


Most case of this kind of issue can be seen when SQLite DB has blob-type field whose data is quite big, and Cursor that includes this field is used at Aadapter.

In this case, Cursor easily exceeds it's maximum Window size (at Android 4.0.3, this value is about 2 MB).

After reaching to maximum Window size, Cursor need to handle Window, and at worse, field size is quite big.
So, whenever move to another row of Cursor, Cursor should handle quite complex disk operation.

So, at this moment, scrolling list becomes very very slow.


To avoid this, main Cursor of Adapter would better not to have big-size field of DB Table.

Instead of it, try to read from DB whenever the field value is demanded.


Then, average time for scrolling list may be increased. But, even at worst cases, list can show reasonable scrolling performance.


신고
Trackback 0 : Comment 0

[Android] Way to avoid using 'notifyDataSetChanged' when only one or two items are changed at Adapter.

Domain/Android 2012.10.23 09:07

When using Adapter (especially list), sometimes(actually very frequently) data of only one item(row) is changed.

In this case, usually, changing one-under-lying data is easy.

But, updating only one list item is different story.

To update that item to the screen, - changing look-and-feel regarding changed item -  easiest way is calling notifyDataSetChanged().

But, this re-bind views of all list items. This is wasteful.

To avoid this, we should get View of item associated, and then modify it directly.

At first glance, it is easy and "Item position to View" map seems to be useful. But, it's NOT.

Why?

AdapterView usually reuse Views. So, several positions become to share same view at "position to View" map.
That is, whenever try to update item at specific item, we need to check that that item has valid visible View or not.

But, this is not-easy at current(API 15) Android API.


My suggestion is using "View to position" map(henceforth VPMap).

At AdapterView, View is reused. So, Adapter doesn't have lot's of different Views.

So, key size of the VPMap is not large (usually at most 20~30).

And we can easily update recent valid visible position of View easily at getView() of Adapter.

See below sample code.

private final HashMap<View, Integer> mView2PosMap = new HashMap<View, Integer>();
...
public void
setItemActive(int pos) {
    if (pos == mActivePos)
        return;
    View v = Utils.findKey(mView2PosMap, mActivePos);
    if (null != v)
        setToInactive(v);
    v = Utils.findKey(mView2PosMap, pos);
    if (null != v)
        setToActive(v);

    mActivePos = pos;
}
...
@Override
public View
getView(int position, View convertView, ViewGroup parent) {
    View v;
    if (null != convertView)
        v = convertView;
    else
        v = UiUtils.inflateLayout(mContext, R.layout.row);

    mView2PosMap.put(v, position);
    ...
}
...
public static <k,v> K
findKey(HashMap<View, Integer> map, V value) {
    Iterator<k> iter = map.keySet().iterator();
    while(iter.hasNext()) {
        K key = iter.next();
        if (map.get(key).equals(value))
            return key;
    }
    return null;
}

Like above, with this VPMap we can easily find associated visible View and can update only one-updated-item-View without calling 'notifyDataSetChanged()'.


신고
Trackback 0 : Comment 0