blog.Ring.idv.tw

2010 March

GTK - GtkMozEmbed

.2010.03.11 Flash更新

本文主要實作一個透過GtkMozEmbed內嵌Browser的GTK應用程式。

先安裝Gecko (layout engine)的開發函式庫:

sudo apt-get install libxul-dev

範例程式

#include <gtk-2.0/gtk/gtk.h>
#include <gtkmozembed.h>
#include <mozilla-config.h>
#include <stdio.h>

int main(int argc, char * argv[])
{
        gtk_init(&argc, &argv);
        GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
        g_signal_connect(GTK_OBJECT(window), "destroy",G_CALLBACK(gtk_main_quit), NULL);
        GtkWidget *html = gtk_moz_embed_new();
        gtk_container_add(GTK_CONTAINER(window), html);
        gtk_moz_embed_load_url(GTK_MOZ_EMBED(html), "http://www.youtube.com/watch?v=TGbwL8kSpEk");

        gtk_widget_show_all(window);
        gtk_main();
        return 0;
}

編譯並執行它

gcc test.cpp -o test `pkg-config --cflags --libs gtk+-2.0` `pkg-config --cflags --libs xulrunner-gtkmozembed`
./test

問題來了!看不到Flash咧~ 這樣就看不到Girls' Generation的MV了.. Orz

2010.03.11 更新

安裝FlashPlayer (ubuntu 9.10 32bit)

sudo apt-get install flashplugin-installer

很簡單的搞定它了! :p

2010-03-11 00:15:52 | Comments (4)

看泡泡

上禮拜六跑去台中拍照~ 隨手捕捉了一幕。

2010-03-10 00:21:53 | Comments (7)

Adobe AIR - iPhone 山寨版

下載:Adobe AIR - iPhone 山寨版

好久沒有碰Adobe AIR了... 今天動手做了一個Adobe AIR版的iPhone影音播放,不過這其實只是一個披著iPhone外殼的介面,外加一點仿iPhone的功能,並且只「內嵌」了一首Girl Generation - Oh!歌曲~ 不過這都不是重點 XD 純粹只是想練習練習Flash而已~

2010-03-09 23:24:30 | Comments (2)

HBase - TableInputFormat

這篇主要記錄如何將HBase(0.20.3)當作Hadoop MapReduce程式的輸入來源,下述的程式碼很單純的從一個Table取出資料並直接輸出至HDFS上:

import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class TestTableInput
{
	public static class Map extends TableMapper<Text, Text>
	{
		@Override
		public void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException
		{
			String v = Bytes.toString(value.value());
			context.write(new Text(Bytes.toString(value.getRow())), new Text(v));
		}
	}

	public static class Reduce extends Reducer<Text, Text, Text, Text>
	{
		@Override
		public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException
		{
			context.write(key, new Text(values.iterator().next()));
		}
	}

	public static void main(String args[]) throws Exception
	{
		if(args.length != 2)
		{
			System.out.println("Usage: hadoop jar TestTableInput.jar <table> <output>");
			System.exit(-1);
		}
		
		String tablename = args[0];
		String output = args[1];

		Configuration conf = new Configuration();
		FileSystem fs = FileSystem.get(conf);
		fs.delete(new Path(output), true);

		Job job = new Job(conf, "TestTableInput");
		Scan scan = new Scan();
		TableMapReduceUtil.initTableMapperJob(tablename, scan, Map.class, Text.class, Text.class, job);	
		job.setJarByClass(TestTableInput.class);
		job.setReducerClass(Reduce.class);
		job.setOutputKeyClass(Text.class);
		job.setOutputValueClass(Text.class);
		job.setOutputFormatClass(TextOutputFormat.class);
		TextOutputFormat.setOutputPath(job, new Path(output));

		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}
}

這裡值得注意的有二個地方,一個是Map必須繼承HBase所提供的TableMapper(其實TableMapper也是繼承於Mapper),它用來指定KEYIN和VALUEIN兩個類別,它們分別為:ImmutableBytesWritableResult,而這兩個類別分別對應的Table資料如下:

ImmutableBytesWritable = Row Key

Result = Row Key+Column+Timestamp+Value

另一個值得注意的是在main方式中用到的TableMapReduceUtil.initTableMapperJob()方法,它封裝了一些設定,如下圖所示:

從圖中我們可以知道該方法會幫我們設定InputFormatClass為TableInputFormat,還有一些相關設定,例如:TableInputFormat.INPUT_TABLE用來設定輸入的Table,TableInputFormat.SCAN用來設定Scan(由於Scan是一個物件,所以必須透過convertScanToString()方法來轉碼成Base64編碼)

2010-03-09 21:12:28 | Add Comment

Copyright (C) Ching-Shen Chen. All rights reserved.

::: 搜尋 :::

::: 分類 :::

::: 最新文章 :::

::: 最新回應 :::

::: 訂閱 :::

Atom feed
Atom Comment