Saturday, January 30, 2016

fluent interface

Fluent interface就是用chaining的方式连接各个行为

在Events类里面所有函数返回该类的指针即可,如











主类调用:




但是getList的循环调用就不适合。

Thursday, November 5, 2015

Eclipse安装Maven

Maven是管理和下载jar包的工具。

如何安装:
Open Eclipse IDE
Click Help -> Install New Software...
Click Add button at top right corner
At pop up: fill up Name as "M2Eclipse" and Location as "http://download.eclipse.org/technology/m2e/releases"
Now click OK
After that installation would be started.

Go to Window --> Preferences
Observe, Maven is enlisted at left panel
Finally,

项目配置
Click on an existing project
Select Configure -> Convert to Maven Project

Monday, August 3, 2015

How to see websocket traffic in Chrome and Fiddler

Websocket是HTML5的一个重要功能,它让server和client端建立新的沟通channel, 让推送的功能更加快速。由于其省去每次发header这个步骤,测试表明websocket比Restful API要快三倍以上。不少网站已经开始使用websocket,比如six flags


这个网站可以测试websocket: https://www.websocket.org/echo.html

我们可以两个方法去看数据:
1. Google Chrome
Chrome在network tab可以看到这个websocket,frames可以看到data






2. Fiddler
在4.5版本中,可以加入额外的代码到custom js中:Rules > Customize Rules and add the following function inside your Handlers class,使得websocket数据显示在Log中:

static function OnWebSocketMessage(oMsg: WebSocketMessage) {
    // Log Message to the LOG tab
    FiddlerApplication.Log.LogString(oMsg.ToString());

    /*
    // Modify a message's content
    var sPayload = oMsg.PayloadAsString();
    if (sPayload.Contains("time")) {
        oMsg.SetPayload(sPayload + "... bazinga!");
    }
                          
    */
  }


Tuesday, July 21, 2015

Gmail API for C#

安装:
根据这个Quick start:https://developers.google.com/gmail/api/quickstart/dotnet



权限问题:
static string[] Scopes = { GmailService.Scope.GmailReadonly };

这句代码说明了权限只局限于Read email only,每次运行代码都会先检查权限文件C:\Users\KK\Documents\.credentials(自动生成,如果存在就会Cache)
如果要修改权限,比如改成
tatic string[] Scopes = { GmailService.Scope.GmailReadonly, GmailService.Scope.GmailModify, GmailService.Scope.GmailLabels};
运行代码前先要删除权限文件,因为默认下,它被cached了。





























Thursday, June 4, 2015

Partition in Win7



1. Shrink



2. Confirm shrink(use the default value)



3. New volumn




Thursday, May 28, 2015

Introduction to Xcode


How to add images in Xcode:
New Group images(in fact it shows as a folder)->drag the images to that group->select "copy to destination" in the pop-up window

How to add a new tab to tab bar controller:
drag a view controller to the stroyboard->right click the tab bar controller->(鼠标在黑龙江后面那个点会出现add)add new view controller and connect it to the new controller by dragging a line.


Create a plist:
http://nscookbook.com/2013/02/ios-programming-recipe-13-using-property-lists-plists/

Tuesday, May 19, 2015

Android加密算法: java变成jar然后到dll

Android用定制的BouncyCastle (轻量级加密算法)并且去除key长度限制

1. Java AES encrypt example:

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;

public class Encryptor {
    public static String encrypt(String key1, String key2, String value) {
        try {
            IvParameterSpec iv = new IvParameterSpec(key2.getBytes("UTF-8"));

            SecretKeySpec skeySpec = new SecretKeySpec(key1.getBytes("UTF-8"),
                    "AES");
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
            byte[] encrypted = cipher.doFinal(value.getBytes());
            System.out.println("encrypted string:"
                    + Base64.encodeBase64String(encrypted));
            return Base64.encodeBase64String(encrypted);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public static String decrypt(String key1, String key2, String encrypted) {
        try {
            IvParameterSpec iv = new IvParameterSpec(key2.getBytes("UTF-8"));

            SecretKeySpec skeySpec = new SecretKeySpec(key1.getBytes("UTF-8"),
                    "AES");
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
            byte[] original = cipher.doFinal(Base64.decodeBase64(encrypted));

            return new String(original);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {

        String key1 = "Bar12345Bar12345"; // 128 bit key
        String key2 = "ThisIsASecretKet";
        System.out.println(decrypt(key1, key2,
                encrypt(key1, key2, "Hello World")));
    }
}

2. JCE Unlimited Strength installation (java JCE download):
http://stackoverflow.com/questions/6363801/invalidkeyexception-illegal-key-size-java-code-throwing-exception-for-encryp
将local_policy.jar & US_export_policy.jar覆盖JRE security文件夹中的原始jar

3. How to export jar file in Eclipse (non-runnable jar):

if your code refers other libs, you need to copy the lib's source code in the src folder and compile together and can't use it as a jar reference.


4. convert jar to dll/exe for .Net by ikvm:

Ref:
http://stackoverflow.com/questions/15554296/simple-java-aes-encrypt-decrypt-example