2014年4月1日星期二

AngularJS 和卡卡女神說再見!

  不知道大家會不會有這個問題,AngularJS 在開發上雖然很方便,可是當資料量大到一個程度,網頁就會整個大卡。為了不要因為 ngRepeat 變成卡卡網站,最近研究了如何優化 angularJS ngRepeat 的效能。以下來跟大家稍稍分享小小心得。使用 ng-repeat 會導致網頁反應遲緩的原因有兩個,下面整理給大家:

2014年3月22日星期六

AngularJS $q deferred 和 promise

  剛接觸 AngularJS 時,每次看到 $q 和 promise,就開始亂用,久了之後唯一的想法就是:「QQ,不會用有再多保證也沒用阿!」。在耐心看完一些網路資料和書的範例後,才知道 $q 實在是一個簡單又好用的東西,只是不懂為什麼大部分的資料似乎都把它講的很玄...,因此決定在這邊記錄和分享一下。

2014年1月5日星期日

AngularJS Service, Factory, Provider 差別

   初學 AngularJS 時,看到 service, factory, provider, 常讓人摸不著頭腦。在網路上survey了一陣,StackOver flow 上最被推崇的一篇:Angular.js: service vs provider vs factory?*1 看了之後還是不解其惑。直到最近在閱讀Pawel 的 Mastering Web Application Development with AngularJS*2,裡面有了詳細的說明,讓我瞬間有豁然開朗之感。以下是一些小小的整理。

2013年1月14日星期一

Add code column in Blogger

References:
http://code.google.com/p/syntaxhighlighter/
http://oneqonea.blogspot.tw/2012/04/how-do-i-add-syntax-highlighting-to-my.html
http://www.vixual.net/blog/archives/198

Decompress (extract) .tgz file in Java

To handle .tgz file, here is a method to handle it in java like handle Zip file.
Use GZIPInputStream to read .tgz file.
Use TarInputStream to read the the GZIPInputStream.
Therefore we can get TarEntry and handle the .tgz file.

Here is an example that we would like to get file named version in a .tgz file.
package test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;

public class GZipTest {

 public static void main(String[] args) {
  byte[] buffer = new byte[1024];
  String fileSorce = "/Users/Desktop/testgzip.tgz";

  try {
   // get the zip file content
   TarInputStream zis = new TarInputStream(new GZIPInputStream(
     new FileInputStream(new File(fileSorce))));
   // get the zipped file list entry
   TarEntry ze = zis.getNextEntry();

   while (ze != null) {
    String fileName = ze.getName();
    if (fileName.contains("version")) {
     StringBuffer strBuffer = new StringBuffer();
     while (zis.read(buffer) > 0) {
      strBuffer.append(new String(buffer));
     }
     System.out.println(strBuffer.toString());
    }
    ze = zis.getNextEntry();
   }

   zis.close();
  } catch (IOException e) {
   System.out.println(e);
  }
 }
}

2012年8月21日星期二

Get Android source code from .apk

To get Android source code from .apk, you need following tools:

  1. dex2jar - the tool helps we decode .apk to .class files
  2. JD-gui or JDEclipse - the tool helps we read the .class files. JD-gui can help you save all .class to .java at one time.
  3. android-apktool - the tool helps we get res and other properties in the .apk.

The steps to get the source code of XXX.apk:

The environment I used is Fedora 16. android-apktool was installed under /usr/local/bin directory.

First, we are going to take the .java files.
     1.  Use dex2jar to get the .class files.
          # sh dex2jar.sh XXX.apk
     Then we will get a file named "XXX.apk.dex2jar.jar". 
     2. Open JD-gui and open "XXX.apk.dex2jar.jar" file. (File -> OpenFile -> indicate XXX.apk.dex2jar.jar ).
     3. Save all sources (File -> Save all sources -> to where you want to save the sources and make a name). Then you will get a zip file. Here we named it XXX.zip.

Now we have .java files in XXX.zip.
     
Second, we are going to get other files such as res directory and .xml files in XXX.apk.
     1.  Use android-apktool to get the files.
           # apktool d XXX.apk XXX_dir
     apktool will create XXX_dir. Then in XXX_dir, we have the files. 
     
Finally, we can unzip XXX.zip to XXX_dir/src. And everything is done.

References:

2012年6月1日星期五

Set up a CloudStack development Environment

I. Set up the development environment
Following are a brief steps of setting up CS development Environment. For the detail steps, check Citrix document 132013.
  1. Install Java JDK.
  2. Install Apache TomCat. (Avoid Tomcat 6.0.35, since it has some problem with CloudStack).
  3. Install Apache ANT.
  4. Install git.
II. Use Eclipse to develop

Import CS src to Eclipse:
Since CloudStack uses Java, it's easier to use Eclipse to develop our own program. After done the first part, all we need to do is to import the CS source code to Eclipse. Check the importing source to Eclipse part of CloudStack document.

Import Eclipse preference:
CloudStack provides the Eclipse preference, just download the attachment in the article, and import it into Eclipse. File->import->General->Preferences->the download file location.

III. Errors in Eclipse:
After CS src was imported to Eclipse, there are many errors. most of them is because awsapi this project. 
awsapi project missed its Libraries. We just need to add the missed jars to it. The missed jars are in project deps/awsapi-lib. Add all jars in awsapi project, then lots of errors can be solved.

For other errors, still checking...