Android SDK: 2.2 API level 8

Eclipse version: Indigo

First download the Facebook-Android SDK – https://github.com/facebook/facebook-android-sdk/

Following is the code of main Activity class, Simply bind the login, logout and post button to the method would work.

package cis542.facebook;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import com.facebook.android.*;
import com.facebook.android.AsyncFacebookRunner.RequestListener;
import com.facebook.android.Facebook.*;

public class FacebookPostWallActivity extends Activity {
	Facebook facebook = new Facebook("YOUR_APP_ID");

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		facebook.authorizeCallback(requestCode, resultCode, data);
	}

	// LOG IN BUTTON
	public void onButtonLogin(View v) {
		facebook.authorize(this, new DialogListener() {
			@Override
			public void onComplete(Bundle values) {
			}

			@Override
			public void onFacebookError(FacebookError error) {
			}

			@Override
			public void onError(DialogError e) {
			}

			@Override
			public void onCancel() {
			}
		});
	}

	// LOG OUT
	public void onButtonLogout(View v) {
		AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(facebook);
		mAsyncFbRunner.logout(getBaseContext(), new RequestListener() {
			@Override
			public void onComplete(String response, Object state) {
			}

			@Override
			public void onIOException(IOException e, Object state) {
			}

			@Override
			public void onFileNotFoundException(FileNotFoundException e,
					Object state) {
			}

			@Override
			public void onMalformedURLException(MalformedURLException e,
					Object state) {
			}

			@Override
			public void onFacebookError(FacebookError e, Object state) {
			}
		});
	}

	// POST BUTTON
	public void onButtonClick(View v) {
		// AsyncFacebookRunner mAsyncFbRunner = new
		// AsyncFacebookRunner(facebook);
		Bundle params = new Bundle();
		params.putString("message", "whatever");
		params.putString("name", "CIS542 porject");
		params.putString("caption", "123456");
		params.putString("link", "http://www.baidutama.com");
		params.putString("description",
				"OUR CIS542 project - by Jason, Jiumei, Eric");
		params.putString("picture", "http://twitpic.com/show/thumb/6hqd44");
		facebook.dialog(this, "feed", params, new PostDialogListener());
	}

	private class PostDialogListener implements DialogListener {
		@Override
		public void onComplete(Bundle values) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onFacebookError(FacebookError e) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onError(DialogError e) {
			// TODO Auto-generated method stub
		}

		@Override
		public void onCancel() {
			// TODO Auto-generated method stub
		}
	}
}

“Real-time” programming: has a fixed deadline, specific time constraints.

soft RT: it would be nice if X happens within Y seconds
hard RT: it would be a disaster if X does not happen within Y seconds

example: Android not responding (ANR)
- Why is RT programming hard?
execution environment is non-deterministic:
- you don’t know what will happen
- you don’t know when it will happen (or how long)
C program in Linux
Sources of non-determinism
1. Scheduling of other processes
2. Cache misses
3. Virtual memory page fault
4. Interrupts with higher priority
* All of these occur in the OS!
* OS usually cares about the case; RT cares about the worst case
Linux scheduling
- Round Robin
- every process gets  small amount of time to run
RT support in POSIX
1. priority-based preemptive scheduling
 - a RT process has a high priority
 - can only be preempted by a higher priority process issues:
     1. user space processes are usually lower priority than kernel space
     2. starvation
     3. priority inversion
2. virtual memory locking
- entire address space of process i locked in physical memory when process starts (no paging)
RTLinux
- RT OS based on Linux
- standard Linux is run as the “idle” process along with non-RT processes
- non-RT processes only run if there are no RT processes to run
- RT process will always preempt non-RT process
- RT processes use RT scheduling algorithms
Scheduling
1. Round Robin (non-RT) each process gets a time slice
2. Priority-based preemptive: process can only be preempted by one with higher priority
3. Rate monotonic Scheduling (RT algorithm) assumes processes are periodic & run in fixed bursts
4. Earliest Deadline First (RT algorithm)
- assumes we know the deadline in advance
- a running task is only preempted by another task that has an earlier deadline
Real-time Java
Sources of non-determinism in Java
1. Garbage collector
- runs when the heap if full – or whatever
- all threads stop when GC runs
2. thread scheduling
- the VM doesn’t have to honor thread priorities
- even so, it’s only relative to other threads in VM
3. JIT complier
4. class loader

First, static files:

1. cd webapps/

2. mkdir new/ (you name it)

3. copy all static html files here

If you further need it to support JSP and Servlet

1. Use ANT to build the java project

2. Copy target/WEB-INF folder into new/ (copy the whole WEB-INF folder, not just content)

3. Replace WEB-INF/web.xml with your web.xml if needed

4. Modify web.xml file to meet tomcat if needed (like no “load-on-startup”)

If everything is good, you can see your html files and servlet under domain http://localhost:8080/new/

Good luck!

Image

好久没有写新番完结小总结了,不过这次这些新番的完结确实让我还挺有感受的。其实这次我看的新番也没几个,就先说说2012年4月具体哪些新番完结了吧:

灼眼的夏娜F 4星
想当年在寝室,一开始还是在墙上看到夏娜的这张海报才看的夏娜。那个时候我还不知道什么钉宫理惠的,但是夏娜的剧情和制作真的是相当的赞啊。有轻松娱乐的校园生活,有紧张的打怪练级,有两人感情的慢慢成长。夏娜那份傲娇更是深入人心。夏娜F怎么说呢,上一部留下的巨大悬念算是给了个答案,但是以上来悠二就和夏娜站在对立面,然后就是各种紧张的对决,早早的进入了高潮然后就各种打架,没了往日的轻松愉快,也看不到夏娜的傲娇和卖萌了。看到的只有夏娜的决心和实力突然变的真的很强。故事确实是高潮迭起打斗非常精彩,最后算是夏娜征服了悠二一个不错的happy ending。但是啊。。。看着就是不带感啊。。不傲娇不卖萌的夏娜还是夏娜么?。。。

零之使魔F 5星
又是钉宫四萌之一完结咯,看来钉宫四萌就剩旋风管家能继续出了。看着这些经典作品完结还挺伤心的。。。好啦,回到正题。零之使魔就完全是以前的风格,很多小故事串在一起,非常有趣的一段段故事还有614继续各种傲娇卖萌,以及才人各种开后宫哈哈。现在才人都有了自己的豪宅了后宫真是开的更是如鱼得水了啊哈哈。。。看到教皇被吃掉那一集我还是觉得挺雷的,这教皇真是死的毫无意义啊。。。最后结局也挺有意思的才人开着战斗机回来拯救世界了。然后happy ending。。。两个人居然结婚了!!!你们不还是高中生大丈夫么?!!还有最后一个镜头居然是614去拜见岳父岳母大人。。。两个人匆匆忙忙跑回家我还以为要干啥呢。。。整体上呢,故事情节相对于前作有点简单,但是毕竟是后宫搞笑为主的作品还是非常看的!顺便一说我挺喜欢这次的ED的,很可爱的说~

high school DxD 4星
观看提示:这是一部刷下限的动漫作品,大家看的时候请自觉脑内打码。。。后宫加热血的作品,自然是狗血的剧情最后男主角最后一集把反派boss虐了成功抢婚。确实有些地方还是很有看点的,比如这种后宫男主角很少有这么H的人的。。。梨斗那种温柔+迟钝的才是主流。。。要不然就渣诚了。。。总之就这么一部总是差一点点就变成H动画的作品,很是搞笑加上故事性也不错。就是最后的结局有点太简单太无脑热血漫画了。。。尼玛上一集还被boss的手下虐下一集就虐boss了。。。boss有这么菜么?。。。另外值得一提这片子的ED真是。。。大家懂得。。。

恶魔奶爸 4星
这个片子是出了好几个季度了然后突然完结了。一开始真的是挺搞笑的,很有点银魂的感觉。魔王的小孩小Baby来人间找了个恶魔奶爸,然后有了各种暴力以及搞笑的故事。而且小贝鲁酱也挺可爱的。。。后来变得有点单调就开始没那么好看了。但是整体还是非常有趣的动漫,也算是没看完一集我都想看下一集的那种。然后啊。。。最后。。。为了打boss之前做了好久好久的铺垫,什么主角怎么修炼的啊,两边的小摩擦啊,最后boss大军终于来啦!然后。。。。。。。。。。。。。。。。尼玛一集就完结了!!!坑爹那你!!!就莫名奇妙boss说不来消灭人类了,然后就没有然后了。。。这也行啊。。。这摆明了是你们不想画了嘛!!!能对观众负责点么!!!

总之呢,我也就看了这么4部片子,夏娜是高潮太多太长导致审美疲劳了,恶魔奶爸和high school都是高潮刚来或者还没来就结束了,就零之使魔还正常点。。。不过当然判断一部片子不要光看结尾的高潮咯,每一集都有意思才行。所以这4部片子我都才一直看到了最后啦~ 4部里面钉宫两萌应该是完结了,恶魔奶爸就是坑爹完结估计是发行商不想出了,high school最后还留了个伏笔估计以后还是有可能出个2之类。另外想起去年的绯弹的亚里亚,居然不是长篇。。。啥时候出2呀。。。

说到结尾,4部片子有3部最后一集都有空中接吻啊,路易斯是开着战斗机,high school是骑着狮鹫还是龙鹰神马的,夏娜自然是自己飞的 – 2个人都会飞。。。恶魔奶爸也有2个人在空中深情对视,但是由于是纯热血的片子就没有然后了。。。
就想到这些了,毕竟也过了一段时间了我才想起来去写这么一个东西。顺便一提前2天了看了一下新出的圣斗士星矢omega。。。瞎了我的眼镜啊!!!肯定是我打开的方式不对。。。我不相信这是车田正美画的啊!!!这绝对是你们原创YY出来的剧情好不好!!!真是天雷滚滚,先不说那奇葩的少女作品画风画的星矢和鲁鲁修一样,且不提那个不知道哪里跑出来的奇葩反派角色,雅典娜你的圣斗士们呢???除了星矢一个黄金的都没了???5小强全挂了只能靠一个白银的撑撑场子了???你这么多年都干嘛去了,多去色诱点新的来呀~。。。光牙也是,人家雅典啊是星矢的妹子啊,星矢为了雅典娜上天入地什么海王冥王什么太阳神都灭过,你一个小屁孩就要NTR纱织小姐啦?。。。总之就是这么一部节操掉了一地的片子,名字叫圣斗士星矢就是噱头,真的是和圣斗士星矢蛋关系都没有的剧情。

- つづく -

Today I had an on-site interview with a company called SSI – Street Solutions Inc. It is a companies with about 50 employee, working on develops, markets and supports technology platforms for secondary loan businesses. However they only have 4 programmer, while most people are Business Analyst, and some PM. While located in Jersey City, it is just by the river, and across the river is New York Manhattan. The office is on the 29th floor on Plaza five, had a great view on the river, where you can even see The Status of Liberty and hot area NYC. And the office is just one stop away from NYC taking a train. The area is cool, lots of modern high buildings, yet there is little people there. Seems it is an area in development.

So – to catch up with the 9am interview, I got up in 5:30am, took a shower, took a cab to Amtrak station, took Amtrak to Newark Penn Station, at last took Path Train red line to Exchange Place Station, walked two blocks to Plaza five. It was terribly cold in the morning, and I did not sleep well so I felt pretty bad.

Anyway I got there just in time, and we three programmer are put together to a room to d some online coding. They have a software called TopCoder which basic have some coding problems, and enable compiling and testing. I finished 4 problems, and still debugging the 5th one when time’s out. In this part I was doing much better than the other two programmers. The questions are:

1. Noob problem, ignore.

2. For a n*m rectangle, how many non-square rectangle can you find in it?

- Just some math, and coding is fairly easy.

3. For integer n<m, what’s the sum of all the digits of all numbers from n to m?

- Example: n = 10, m = 14, sum = (1 + 0) + (1 + 1) + (1 + 2) + (1 + 3) + (1 + 4) = 15

- My alg was to calculate sum of 1s, 10s, 100s…  Although there is only about 20 lines of code, there are many details and it was quite a pain to debug it, finally made it work correctly.

4. ThreePorter, some noob brutal-force problem

5. Possibility of coloring, brutal-force + Permutations

After that we spent half an hour working with guys applying for Business Analysts together for a design of iPhone application, which is basic schedule and score board for PingPong games – pretty dumb. Afterward we had lunch, chatted. It is quite disappointing that seldom people play Basketball there. Instead they are very fond of PingPong, and had a PingPong table in the office.

At last one developer and one co-founder interviewed me, asked me some basic OO questions, let me asked some question. Then they let HR walked me out of the building. I was kind of surprised because I thought I did pretty good and should not fail this interview. HR told me there would be another “FINAL on-site interview”…………………… HOLY CRAP!!!!!

Have to assume that all integers are positive, or this alg won’t work.

Basic idea is we keep a head pointer and a tail pointer. If the sum btw head and tail is larger than k, tail ++; if the sum is smaller than k, head ++. At first glance it seems not giving correct answer to all cases. Yet after look into it, it is not hard to prove this alg is perfect.

package interview;

import java.util.ArrayList;

public class FindSum {
	// How do you find sequences of consecutive positive integers in a list that
	// add to a particular number.
	public void findSum(ArrayList list, int sum) {
		int head = 0;
		int tail = 0;
		int total = list.get(0);
		while (true) {
			while (total > sum) { // if total is larger, get rid of head
				total -= list.get(head);
				head++;
			}
			if (total == sum) { // check sum
				for (int i = head; i <= tail; i++) {
					System.out.print(list.get(i) + " ");
				}
				System.out.println("= " + sum);
			}
			tail++; // add tail element
			if (tail == list.size())
				break;
			else
				total += list.get(tail);
		}
	}

	public static void main(String[] args) {
		test1();
	}

	public static void test1() {
		ArrayList test = new ArrayList();
		test.add(6);
		test.add(3);
		test.add(7);
		test.add(2);
		new FindSum().findSum(test, 13);
		new FindSum().findSum(test, 10);
		new FindSum().findSum(test, 9);
	}
}

This is a problem from OuYang’s Amazon on-site interview:

You have a list of words, in dictionary order. Say “abandon”, “about”, “absolute”, “fool”. Then you know that ‘a’ < ‘o’ < ‘s’ and ‘a’ < ‘f’. According to these input words, print a possible order of the characters. Sample: in this case, output “afos” or “aofs” or “aosf”.

My Alg:

1. For input words, by combine each pair of consecutive words, each combine you may know a fact “x” < “y” (or not)

2. For each character “x”, build a node x. For “x” < “y”, we have a directed link node x -> node y. Thus you build a map.

3. When you output the result, always find the node with no incoming link. Print node value, and delete all outgoing links.

4. Repeat step 3 until there is no node with no incoming link.

Code:

package interview;

import java.util.*;

// start to program at 10:50pm
// finish in 11:16pm, Hooray!
public class FindDictionaryOrder {
	// A node in the map
	private class Node {
		public char value;
		public ArrayList incoming = new ArrayList();
		public ArrayList outgoing = new ArrayList();
		public boolean checked = false;

		public Node(char v) {
			value = v;
		}
	}

	private HashMap nodes = new HashMap();

	// find relation two Strings
	private void findRelation(String s1, String s2) {
		int c1 = 0;
		int c2 = 0;
		while (true) {
			if (c1 >= s1.length() || c2 >= s2.length())
				return; // no useful information
			if (s1.charAt(c1) != s2.charAt(c2))
				break;
			c1++;
			c2++;
		}
		char ch1 = s1.charAt(c1);
		char ch2 = s2.charAt(c2);
		// System.out.println(ch1 + " < " + ch2);
		if (!nodes.containsKey(ch1))
			nodes.put(ch1, new Node(ch1));
		if (!nodes.containsKey(ch2))
			nodes.put(ch2, new Node(ch2));
		Node n1 = nodes.get(ch1);
		Node n2 = nodes.get(ch2);
		if (!n1.outgoing.contains(n2))
			n1.outgoing.add(n2);
		if (!n2.incoming.contains(n1))
			n2.incoming.add(n1);
	}

	public void inputWord(ArrayList words) {
		String first = words.get(0);
		System.out.print(first + " ");
		String second;
		for (int i = 0; i < words.size(); i++) {
			second = words.get(i);
			System.out.print(second + " ");
			findRelation(first, second);
			first = second;
		}
	}

	private void printNode(Node n) {
		System.out.print(n.value);
		for (int i = 0; i < n.outgoing.size(); i++) {
			n.outgoing.get(i).incoming.remove(n);
		}
		n.checked = true;
	}

	public void printOrder() {
		System.out.println();
		boolean flag = true;
		while (flag) {
			char c;
			for (c = 'a'; c  'z')
				break;
		}
		System.out.println();
	}

	public static void main(String[] args) {
		test1();
		test2();
	}

	public static void test2() {
		ArrayList words = new ArrayList();
		words.add("ac");
		words.add("ab");
		words.add("abc");
		words.add("aba");
		words.add("abd");
		words.add("ad");

		FindDictionaryOrder find = new FindDictionaryOrder();
		find.inputWord(words);
		find.printOrder();
	}

	public static void test1() {
		ArrayList words = new ArrayList();
		words.add("ab");
		words.add("abc");
		words.add("abd");
		words.add("abde");
		words.add("abf");
		words.add("ag");

		FindDictionaryOrder find = new FindDictionaryOrder();
		find.inputWord(words);
		find.printOrder();
	}
}