2010년 4월 7일 수요일

Set과 List

javadoc 에 나온 설명을 보면

Set - A collection that contains no duplicate elements.
List - Unlike sets, lists typically allow duplicate elements.

요지는, 유니크한 객체를 담아두려고 list 만들고
list.contains(o) 로 체크하는 삽집을 하면 안된다는 것.
(3배 빠른...이 아니라 300배 느림을 경험하게 된다.)

list 정렬은
Collections.sort(list, new Comparator<T>() {

            @Override
            public int compare(T o1, T o2) {
                // TODO Auto-generated method stub
                return 0;
            }
        });

set 은
Set<T> set = new TreeSet<T>(new Comparator<T>() {

            @Override
            public int compare(T o1, T o2) {
                // TODO Auto-generated method stub
                return 0;
            }
        });

기초는 중요하다...

2010년 3월 31일 수요일

Spring 에서 Velocity DatasourceResourceLoader 쓰기.

환경: spring 2.5, velocity 1.5

화면 커스터마이징 요구는 많은데, 건건이 받아서 올리고 배포하고 하려니 골치 아파서 찾아본 해결책.
기존 파일로 존재하는 vm 파일도 그대로 쓰고, 없으면 db에서 가져오게 하는게 요점.


<bean id="dsVelocityEngine"
    class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
    <property name="resourceLoaderPath" value="/WEB-INF/vm"></property>
    <property name="velocityPropertiesMap">
        <map>
            <entry key="resource.loader" value="file,ds"></entry>                   
            <entry key="ds.resource.loader.instance">
                <ref bean="templateLoader"/>
            </entry>
            <entry key="ds.resource.loader.resource.table">
                <value>vm_templates</value>
            </entry>
            <entry key="ds.resource.loader.resource.keycolumn">
                <value>name</value>
            </entry>
            <entry key="ds.resource.loader.resource.templatecolumn">
                <value>content</value>
            </entry>
            <entry key="ds.resource.loader.resource.timestampcolumn">
                <value>updated</value>
            </entry>
            <entry key="input.encoding" value="utf-8"></entry>
            <entry key="output.encoding" value="utf-8"></entry>
            <entry key="directive.foreach.counter.name" value="velocityCount"></entry>
            <entry key="directive.foreach.counter.initial.value" value="0"></entry>
        </map>
    </property>
</bean>

<!-- Velocity Database Template Loader -->
<!-- dataSource bean은 이미 정의되어 있음 -->
<bean id="templateLoader"
    class="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader">
    <property name="dataSource" ref="dataSource"></property>
</bean>
   

    <!-- Velocity Configurer -->
<!--
configurer 에서 velocityEngine 을 잡을 경우,
resourceLoaderPath나 기타 velocity property 는 여기가 아닌 velocityEngine 에서 설정해줘야 된다.
-->
    <bean id="velocityConfigurer"
        class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
        <property name="velocityEngine" ref="dsVelocityEngine"></property>       
    </bean>

    <!-- Velocity Resolver -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <property name="exposeRequestAttributes" value="true" />
        <property name="exposeSessionAttributes" value="true" />
        <property name="contentType" value="text/html; charset=UTF-8" />
        <property name="cache" value="true" />    
        <property name="suffix" value=".vm" />
        <property name="viewClass" value="org.springframework.web.servlet.view.velocity.VelocityView" />
    </bean>


UIView 의 Tag

To search for a tagged view, use the viewWithTag: method of UIView. This method searches the receiver ’s
subviews using a depth-first search, starting with the receiver itself.

- iPhoneAppProgrammingGuide

for loop 를 돌릴 필요가 없구나.

대충 이런 코드?
// ViewController 에서.
UView *v = [self.view viewWithTag:tag];


2010년 3월 16일 화요일

rails type 필드명 읽기.

legacy table에 type 필드명 있을 때.

  class Thing < ActiveRecord::Base
def type
read_attribute :type
end

def type=( new_type )
write_attribute :type, new_type
end
end

Single Table Inheritance 의 inheritance column 명도 바꿔줌.

 @inheritance_column = "sti_type"

참고
http://lists.rubyonrails.org/pipermail/rails/2006-January/009209.html

중궈 IT 애들은 구글 없어지면 어떻게 일하려나.
난 사표 써야할 거 같은데...

2010년 3월 12일 금요일

core data migration

Remember to clean all your targets before trying again, to avoid the can’t merge models with two different entities named ‘Person’. error

Core Data migration 설정 후에 실행했는데

"avoid the can’t merge models with two different entities named 어쩌구" 에러 났을 때.

Clean 후 다시 실행하면 된다.

참고
* http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreDataVersioning/Introduction/Introduction.html
* http://www.timisted.net/blog/archive/core-data-migration/

2010년 2월 22일 월요일

ruby Time format

쓸 때마다 까먹는...

Formats time according to the directives in the given format string. Any text not listed as a directive will be passed through to the output string.

Format meaning:

  %a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
%j - Day of the year (001..366)
%m - Month of the year (01..12)
%M - Minute of the hour (00..59)
%p - Meridian indicator (``AM'' or ``PM'')
%S - Second of the minute (00..60)
%U - Week number of the current year,
starting with the first Sunday as the first
day of the first week (00..53)
%W - Week number of the current year,
starting with the first Monday as the first
day of the first week (00..53)
%w - Day of the week (Sunday is 0, 0..6)
%x - Preferred representation for the date alone, no time
%X - Preferred representation for the time alone, no date
%y - Year without a century (00..99)
%Y - Year with century
%Z - Time zone name
%% - Literal ``%'' character

t = Time.now
t.strftime("Printed on %m/%d/%Y") #=> "Printed on 04/09/2003"
t.strftime("at %I:%M%p") #=> "at 08:56AM"

http://ruby-doc.org/core/classes/Time.html#M000298

2010년 2월 12일 금요일

MFMailComposeViewController


app 안에서 메일을 보낼 때.

UApplication의 openURL 을 이용하면 현재 프로그램이 종료되고, 메일 프로그램이 실행되므로,
어플 안에서 메일만 보내고자 한다면 이걸 사용해야 하는 듯.

-canSendMail  로 메일발송가능한 장비인지 먼저 확인.

뷰를 보여주는건 보통 presentModalViewController:animated:  로 처리하면 된다.

제목, 수신, cc, bcc, 본문, 파일첨부를 위한 메쏘드들이 있다.

*주의사항
메일 인터페이스가 표시된 이후엔, 코드로 내용에 손을 대선 안된다는거.
메일이 잘 발송되었는지도 보장하지 않는다는거. (보낼 편지함에 남을 수도 있고, 보내졌을 수도 있고...)

delegate 는
MFMailComposeViewControllerDelegate

– mailComposeController:didFinishWithResult:error:
메일작성창이 사라질때 호출되고, 결과를 반환

결과 상수
MFMailComposeResult

MFMailComposeResultCancelled 사용자 취소
MFMailComposeResultSaved 임시보관함에 저장.
MFMailComposeResultSent 발송됨 (보낼편지함에 저장)
MFMailComposeResultFailed 에러

Framework: MessageUI

참고
http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html

http://developer.apple.com/iphone/library/documentation/MessageUI/Reference/MFMailComposeViewControllerDelegate_protocol/Reference/Reference.html#//apple_ref/occ/intf/MFMailComposeViewControllerDelegate