2013년 3월 13일 수요일

php 큰따옴표 "" 에서 클래스변수도 먹힐까?


<?php
class test{
var $foo = "ok works";
function test_function(){
echo "aaa ".$this->foo." aaa";
echo "</br></br>";
echo "aaa $this->foo aaa";
echo "</br></br>";
}
}
?>
view raw gistfile1.php hosted with ❤ by GitHub

결과는

aaa ok works aaa
aaa ok works aaa
ㅇㅇ 먹힌다.



노가다를 줄여주는 안드로이드 템플릿

https://github.com/jgilfelt/android-adt-templates

이곳엔 기본 템플릿 외에 유용한 템플릿이 추가되어있다.


사용법

  1. 압축푼 파일을 sdk-folder/extras/templates/ 에 있는 activities 와 others 폴더에 각각 넣는다.
    (난 sdk-folder/tools/templates/ 에 있었음)
  2. New->Other ->Android->Android Object






템플릿들

  • EfficientListAdapter
    매번 리스트를 만드려면 view holder 패턴을 작성해야되는데 이를 편리하게 하여준다

    public class ItemAdapter extends BaseAdapter
    {
    // TODO replace with a collection of real data
    private static final List<DummyItem> DATA = DummyItemContent.ITEMS;
    private LayoutInflater mInflater;
    public ItemAdapter(Context context)
    {
    // Cache the LayoutInflate to avoid asking for a new one each time.
    mInflater = LayoutInflater.from(context);
    }
    /**
    * @see android.widget.ListAdapter#getCount()
    */
    public int getCount()
    {
    return DATA.size();
    }
    /**
    * @see android.widget.ListAdapter#getItem(int)
    */
    public Object getItem(int position)
    {
    return DATA.get(position);
    }
    /**
    * Use the array index as a unique id.
    *
    * @see android.widget.ListAdapter#getItemId(int)
    */
    public long getItemId(int position)
    {
    return position;
    }
    /**
    * Make a view to hold each row.
    *
    * @see android.widget.ListAdapter#getView(int, android.view.View,
    * android.view.ViewGroup)
    */
    public View getView(int position, View convertView, ViewGroup parent)
    {
    // A ViewHolder keeps references to children views to avoid unneccessary
    // calls
    // to findViewById() on each row.
    ViewHolder holder;
    // When convertView is not null, we can reuse it directly, there is no
    // need
    // to reinflate it. We only inflate a new View when the convertView
    // supplied
    // by ListView is null.
    if (convertView == null)
    {
    convertView = mInflater.inflate(R.layout.list_item_item, parent,
    false);
    // Creates a ViewHolder and store references to the two children
    // views
    // we want to bind data to.
    holder = new ViewHolder();
    // TODO store references to your views
    holder.title = (TextView) convertView.findViewById(R.id.title);
    holder.subtitle = (TextView) convertView
    .findViewById(R.id.subtitle);
    holder.thumbnail = (ImageView) convertView
    .findViewById(R.id.thumbnail);
    convertView.setTag(holder);
    }
    else
    {
    // Get the ViewHolder back to get fast access to the TextView
    // and the ImageView.
    holder = (ViewHolder) convertView.getTag();
    }
    // TODO Bind your data efficiently with the holder.
    holder.title.setText(DATA.get(position).content);
    holder.subtitle.setText(DATA.get(position).content);
    holder.thumbnail.setImageResource(DATA.get(position).thumbnail);
    return convertView;
    }
    static class ViewHolder
    {
    // TODO define members for each view in the item layout
    TextView title;
    TextView subtitle;
    ImageView thumbnail;
    }
    }
    view raw gistfile1.java hosted with ❤ by GitHub
  • ParcelableType
    Parcelable 클래스 템플릿
    public class NameCard implements Parcelable
    {
    // TODO declare your real class members
    // Members must be either primitives, primitive arrays or parcelables
    private int mFoo;
    private String mBar;
    // TODO implement your constructors, getters & setters, methods
    private NameCard(Parcel in)
    {
    // TODO read your class members from the parcel
    // Note: order is important - you must read in the same order
    // you write in writeToParcel!
    mFoo = in.readInt();
    mBar = in.readString();
    }
    @Override
    public void writeToParcel(Parcel out, int flags)
    {
    // TODO write your class members to the parcel
    // Note: order is important - you must write in the same order
    // you read in your private parcelable constructor!
    out.writeInt(mFoo);
    out.writeString(mBar);
    }
    @Override
    public int describeContents()
    {
    // TODO return Parcelable.CONTENTS_FILE_DESCRIPTOR if your class members
    // include a FileDescriptor, otherwise you can simply return 0
    return 0;
    }
    public static final Parcelable.Creator<NameCard> CREATOR = new Parcelable.Creator<NameCard>() {
    public NameCard createFromParcel(Parcel in)
    {
    return new NameCard(in);
    }
    public NameCard[] newArray(int size)
    {
    return new NameCard[size];
    }
    };
    }
    view raw gistfile1.java hosted with ❤ by GitHub
  • Sherlock 템플릿들
    기본 activity 와 같은 템플릿으로 Sherlock 라이브러리를 사용하여 생성
  • TVLeftNavBarActivity
    google TV 를 위한 것이라고 한다. 원문참고

    This template creates a new blank activity with a left navigation/action bar implementation optimized for Google TV. You can select different visual behaviors (expanded, collapsed, or expand on focus) and navigation modes (standard, tabs or list). This template has a dependency on the Google TV LeftNavBarLibrary project which is available here.

2013년 3월 12일 화요일

restful 테스트 쉽게 하는곳

post, get data 를 테스트 하기에 좋은 사이트

Postman



크롬을 쓴다면 매우 유용한 도구
13년 5월 20일 현재 926명 평가에 무료 별점 5개를 기록하고 있다.

https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm/related

http://hackst.com/





깔끔한 디자인에 원하던 기능이 모두 있다. history 기능도 있음
가끔씩 접속 안됨


http://www.hurl.it/


심플한 사이트. Ruby 환경이라면 직접 소스를 다운받아 사용할 수 있다.
역시 가끔씩 에러가 뜸

https://apigee.com/console/

twitter, facebook 등등 수십가지의 api 들을 테스트 해볼수 있게 미리 지정되어 있다.
가장 위의 Other 를 선택하면 직접 url 입력이 가능하다.
기업에서 운영하기 때문에 접속이 안되는 일은 없음

java 정규식 빈칸만 있는 문자인지를 체크하고 싶을때

if (string.trim().length() > 0){
// true
}
if (string.matches(".*\\w.*")) {
// true
}
view raw gistfile1.java hosted with ❤ by GitHub


첫번째 : trim 으로 공백을 모두 없앴을때 length 가 0 일때 true

두번째 : /w 로 문자열에 문자가 포함되었는지를 체크, 이 방법은 특수문자만으로 이루어진 글일때 역시 false 를 반환한다

ex) #$@! = false

출처 : http://stackoverflow.com/questions/3247067/how-to-check-that-java-string-is-not-all-whitespaces