Archive for ‘ January, 2010

[Java]FreemarkerでXML(NodeModel)のElementの一覧を表示してみる。

ということで、FreemarkerでXMLの内容を表示したいときに、どんなエレメントが紐づいているのか知りたかったので、
FreemarkerのFunctionを使って表示させtみた。

<#function pprint xmlroot depth>
	<#local ret>
		<#list xmlroot?children as c>
			<#list 0..depth as x>  </#list>
			<#if c?node_type = 'element'>
				- ${c?node_type}
				<#local d = depth + 1>
				${c?node_name}
				${pprint(c, d)}
			</#if><br />
		</#list>
	</#local>
	<#return ret>
</#function>

使い方はこんな感じ

${pprint(xmldoc, 0)}

Popularity: 17% [?]

  • Digg
  • Google Bookmarks
  • Google Reader
  • Facebook
  • Delicious
  • FriendFeed
  • Evernote
  • Twitter
  • Share/Bookmark

[Java]Enumで遊んでみる

長らくJavaをやってなかったら、Enumとかいうのができていたので使ってみた。
使い方あっているのだろうか…


// for later than 1.5
enum KtaiInfoEnum {

	DOCOMO(0, "docomo"),
	SOFTBANK(1, "softbank"),
	AU(2, "au");

	private String carrierName = null;
	private Integer type = 0;
	private KtaiInfoEnum(Integer type, String carrierName) {
		this.type = type;
		this.carrierName = carrierName;
	}
	public Integer getType() {
		return this.type;
	}
	public String getCarrierName() {
		return this.carrierName;
	}
}

// for java 1.4
class KtaiInfo {

	public static final KtaiInfo DOCOMO = new KtaiInfo(0, "docomo");
	public static final KtaiInfo SOFTBANK = new KtaiInfo(1, "softbank");
	public static final KtaiInfo AU = new KtaiInfo(2, "au");

	private String carrierName = null;
	private Integer type = null;
	private KtaiInfo(Integer type, String carrierName) {
		this.type = type;
		this.carrierName = carrierName;
	}

	public Integer getType() {
		return this.type;
	}
	public String getCarrierName() {
		return this.carrierName;
	}

}

public class TestListStructure {

    public static void main(String args[]) {

    	System.out.println(KtaiInfo.SOFTBANK.getType() + ":" + KtaiInfo.SOFTBANK.getCarrierName());
    	System.out.println(KtaiInfoEnum.SOFTBANK.getType() + ":" + KtaiInfoEnum.SOFTBANK.getCarrierName());

    	for(KtaiInfoEnum ktaiInfo: KtaiInfoEnum.values()){
    		System.out.println(ktaiInfo.getType() + ":" + ktaiInfo.getCarrierName());
    	}

    }

}

Popularity: 15% [?]

  • Digg
  • Google Bookmarks
  • Google Reader
  • Facebook
  • Delicious
  • FriendFeed
  • Evernote
  • Twitter
  • Share/Bookmark

[Django]関数ごとmemcacheに入れるための便利関数

こんな感じ。

def cache_func(key, timeout, func, *args, **kwargs):
    # get the result from memcache
    result = memcache.get(key)
    if result:
        return result
    # get the result from orginal function
    result = func(*args, **kwargs)
    # set the result to memcache
    memcache.set(key, result, timeout)
    return result

使い方はこんな感じ。

def get_hogehoge(id, count):
    return "%(id)s_%(count)s"
cache_timelines = lambda id, count: cache_func('cachekey_%(id)s_%(count)s' % dict(id=id, count=count), 60 * 10, get_hogehoge, id, count)

Popularity: 9% [?]

  • Digg
  • Google Bookmarks
  • Google Reader
  • Facebook
  • Delicious
  • FriendFeed
  • Evernote
  • Twitter
  • Share/Bookmark

[PS3]Apple Wireless KyeboardをPS3で使ってみた

ということで、PS3用にWirelessキーボードがほしかったので探してみたところ、

どうやらApple Wireless Keyboard (JIS) MC184J/Aがコスト的にも討ちやすさ的にも、大きさ的にもよかったので、

それを買うことにした。(ちなみに2台目)

IMG_0838

ということで、さっそく使ってみた。

キーボードの電源をいれ、PS3の「設定」の「周辺機器設定」からBluetooth機器を検索して

登録を行う。

IMG_0839

 

 

そんな感じで、普通に登録できた。

日本語変換のON/OFFは「Comand+Space」で行うことができるし、日ごろから打ちなれいるので、

大変使いやすい。

 

ちなみに、ほかのBluetooth接続のキーボードを探してみたが、5000~10000円くらいするので、

Appleのこのキーボードはかなり買いだと思う。

Popularity: 18% [?]

  • Digg
  • Google Bookmarks
  • Google Reader
  • Facebook
  • Delicious
  • FriendFeed
  • Evernote
  • Twitter
  • Share/Bookmark