출처: http://googlekoreablog.blogspot.com/2008/04/robotstxt.html

robots.txt를 현명하게 사용하는 방법

Search Quality팀 석인혁, Chao Ma


검색엔진
 자신의 사이트를 많은 사람에게 알릴 수 있는 가장 좋은 방법 중 하나입니다이를 활용하기에 앞서 고려해야 할 것은 여러분들의 사이트에 있는 정보를 얼마 만큼 외부에 제공할 것인가를 설정하는 일입니다. 

만약 여러분의 사이트에 검색엔진을 통해 색인이 생성되지 않도록 하려는 콘텐츠가 있다면,robots.txt 파일을 사용하여 웹을 색인하는 검색엔진 로봇(이하 "검색봇")을 차단하거나 필요한 부분만을 검색엔진에 나타나게 할 수 있습니다. 검색봇은 자동으로 작동하며한 사이트의 하위 페이지에 접근하기 전에 먼저 특정 페이지에 대한 접근을 차단하는 robots.txt 파일이 있는지 여부를 확인합니다. 이번 기회를 통하여 여러분들에게 올바르게 robots.txt를 사용하는 방법을 제공하고자 합니다.

robots.txt 의 배치

robots.txt는 HTML 파일이 아닌 일반 텍스트 파일로 도메인의 root에 있어야 하며 반드시 'robots.txt'로 저장되야 합니다. 검색봇은 도메인의 root에 있는 robots.txt 파일만을 체크하기 때문에 하위 디렉토리에 있는 파일은 유효하지 않습니다.

예를 들어 http://www.example.com/robots.txt는 유효한 위치이지만,http://www.example.com/mysite/robots.txt는 유효하지 않습니다.

robots.txt 사용 예제:
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/

Disallow: /~name/

robots.txt 파일을 사용하여 전체 웹사이트를 허용/차단하기 


전체 웹사아트를 검색엔진이 색인하도록 허용하고자 할 때에는 다음과 같이 robots.txt 
일을 추가합니다.
User-agent: *
Disallow:

또 다른 해결 방법으로는 단순하게 robots.txt를 사이트로부터 제거 하는 것입니다.

검색엔진에서 사이트를 삭제하고 향후 어떤 검색봇도 접근하지 못하게 하려면 robots.txt 파일에 다음 내용을 추가합니다. 
User-agent: *
Disallow: /

주의) 이 경우 검색봇이 차단되어 사이트가 더이상 검색엔진에 나타나지 않게 됨으로 검색엔진을 통 들어오게 되는 사용자들에게 불이익을 제공하게 됩니다.

각 포트에는 전용 robots.txt 파일이 있어야 합니다. 특히 http와 https 모두를 통해 사용자들에콘텐츠를 제공하려면 이 두 가지 프로토콜에 대해 각각의 robots.txt 파일이 있어야 합니다.

예를 들어 검색봇을 통해 https 페이지를 제외한 모든 http 페이지에 대한 수집을 허용하려면 다음 robots.txt 파일들을 각의 프로토콜에 사용해야 합니다.

http 프로토콜의 경우
(http://yourserver.co.kr/robots.txt): 
User-agent: *
DIsallow:

https 프로토콜의 경우
(https://yourserver.co.kr/robots.txt): 

User-agent: *
Disallow: /

robots.txt 파일을 사용하여 페이지 차단하기

예를 들어검색봇이 특정 디렉토리(: board )의 모든 페이지를 검색하지 않도록 차단하려면 다음과 같이 robots.txt를 사용 하시면 됩니다.
User-agent: *
Disall
ow: /board/

Googlebot이 특정 형식(: .gif)의 파일을 모두 검색하지 않도록 차단하려면 다음과 같이robots.txt를 사용 하시면 됩니다.
User-Agent: Googlebot
Disallow: /*.gif$

Googlebot이 ?가 포함된 URL 즉, 도메인 이름으로 시작되거나 임의의 문자열 또는 물음표로 구성된URL 검색을 차단하려면 다음과 같이 하시면 됩니다. 
User-agent: Googlebot
Disallow: /*?

구글은 웹마스터 도구의 일원으로 robots.txt 분석 도구를 사용자들에게 제공하고 있습니다. robots.txt 분석도구는 여러분의 robots.txt 화일을 검색봇이 읽는 그대로 인식하여 그 결과를 여러분들께 제공하고 있습니다. robots.txt의 올바른 사용으로 사이트 방문자에게 보다 쉬운 접근 방법을 제공하는 동시에 필요한 부분을 보호, 차단할 수 있기 바랍니다.

  

Avoiding Memory Leaks

Android applications are, at least on the T-Mobile G1, limited to 16 MB of heap. It's both a lot of memory for a phone and yet very little for what some developers want to achieve. Even if you do not plan on using all of this memory, you should use as little as possible to let other applications run without getting them killed. The more applications Android can keep in memory, the faster it will be for the user to switch between his apps. As part of my job, I ran into memory leaks issues in Android applications and they are most of the time due to the same mistake: keeping a long-lived reference to a Context.

On Android, a Context is used for many operations but mostly to load and access resources. This is why all the widgets receive a Context parameter in their constructor. In a regular Android application, you usually have two kinds of ContextActivity and Application. It's usually the first one that the developer passes to classes and methods that need a Context:

@Override
protected void onCreate(Bundle state) {
 
super.onCreate(state);
 
 
TextView label = new TextView(this);
  label
.setText("Leaks are bad");
 
  setContentView
(label);
}

This means that views have a reference to the entire activity and therefore to anything your activity is holding onto; usually the entire View hierarchy and all its resources. Therefore, if you leak the Context ("leak" meaning you keep a reference to it thus preventing the GC from collecting it), you leak a lot of memory. Leaking an entire activity can be really easy if you're not careful.

When the screen orientation changes the system will, by default, destroy the current activity and create a new one while preserving its state. In doing so, Android will reload the application's UI from the resources. Now imagine you wrote an application with a large bitmap that you don't want to load on every rotation. The easiest way to keep it around and not having to reload it on every rotation is to keep in a static field:

private static Drawable sBackground;
 
@Override
protected void onCreate(Bundle state) {
 
super.onCreate(state);
 
 
TextView label = new TextView(this);
  label
.setText("Leaks are bad");
 
 
if (sBackground == null) {
    sBackground
= getDrawable(R.drawable.large_bitmap);
 
}
  label
.setBackgroundDrawable(sBackground);
 
  setContentView
(label);
}

This code is very fast and also very wrong; it leaks the first activity created upon the first screen orientation change. When a Drawable is attached to a view, the view is set as a callback on the drawable. In the code snippet above, this means the drawable has a reference to theTextView which itself has a reference to the activity (the Context) which in turns has references to pretty much anything (depending on your code.)

This example is one of the simplest cases of leaking the Context and you can see how we worked around it in the Home screen's source code (look for the unbindDrawables() method) by setting the stored drawables' callbacks to null when the activity is destroyed. Interestingly enough, there are cases where you can create a chain of leaked contexts, and they are bad. They make you run out of memory rather quickly.

There are two easy ways to avoid context-related memory leaks. The most obvious one is to avoid escaping the context outside of its own scope. The example above showed the case of a static reference but inner classes and their implicit reference to the outer class can be equally dangerous. The second solution is to use the Application context. This context will live as long as your application is alive and does not depend on the activities life cycle. If you plan on keeping long-lived objects that need a context, remember the application object. You can obtain it easily by calling Context.getApplicationContext() or Activity.getApplication().

In summary, to avoid context-related memory leaks, remember the following:

  • Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself)
  • Try using the context-application instead of a context-activity
  • Avoid non-static inner classes in an activity if you don't control their life cycle, use a static inner class and make a weak reference to the activity inside. The solution to this issue is to use a static inner class with a WeakReference to the outer class, as done in ViewRoot and its W inner class for instance
  • A garbage collector is not an insurance against memory leaks

    출처:  http://developer.android.com/resources/articles/avoiding-memory-leaks.html
  

Java의 9가지 네이밍 관습들

Posted by epicdev Archive : 2011. 9. 8. 23:49

9 - Naming Conventions

Naming conventions make programs more understandable by making them easier to read. They can also give information about the function of the identifier-for example, whether it's a constant, package, or class-which can be helpful in understanding the code.


Identifier Type


Rules for Naming


Examples


Packages


The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently com, edu, gov, mil, net, org, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.

Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.

com.sun.eng

com.apple.quicktime.v2

edu.cmu.cs.bovik.cheese


Classes


Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).


class Raster; 
class ImageSprite;


Interfaces


Interface names should be capitalized like class names.


interface RasterDelegate; 
interface Storing;


Methods


Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized.


run(); 
runFast(); 
getBackground();


Variables


Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are ijkm, and n for integers; cd, and e for characters.


int             i;
char            c;
float           myWidth;



Constants


The names of variables declared class constants and of ANSI constants should be all uppercase with words separated by underscores ("_"). (ANSI constants should be avoided, for ease of debugging.)


static final int MIN_WIDTH = 4;

static final int MAX_WIDTH = 999;

static final int GET_THE_CPU = 1;



출처: 
http://www.oracle.com/technetwork/java/codeconventions-135099.html
  
 «이전 1 ··· 47 48 49 50 51 52 53 ··· 55  다음»