posted in iOS 

Days ago I update pod to version 1.0. Then found all header not found in my header bridge file. I spent 2 days to locate the reason. That is cocoaPods.
Thanks to Git, I noticed that Header folder was be deleted after I run pod install which pod 0.x did not do that.
What pod 1.0 do is that I don’t need import headers explicitly any more. Pod do that.
So what I need to do is DELETE all import statement which not found. That will fix everything.

posted in Angular 

When I type npm start in my angular2 project, terminal shows:

Subsequent variable declarations must have the same type. Variable '$' must be of type 'JQueryStatic', but here has type 'cssSelectorHelper'
There is a conflict between angular-protractor and jQuery. One soluction I googled is marked down below:

Modify your jquery.d.ts file

declare module "jquery" {
    export = $;
declare var jQuery: JQueryStatic;
declare var $: JQueryStatic;


declare module "jquery" {
    export = jQuery;
declare var jQuery: JQueryStatic;

On the contrary, you can change protractor also.
[1] How to use jquery with angular2

posted in Android 

今天更新了 Android 6.0 的 SDK 后发现项目一片红,吓尿了。
Android 6.0 release removes support for the Apache HTTP client. If your app is using this client and targets Android 2.3 (API level 9) or higher, use the HttpURLConnection class instead. This API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. To continue using the Apache HTTP APIs, you must first declare the following compile-time dependency in your build.gradle file:

android {
    useLibrary 'org.apache.http.legacy'

大概意思就是,Android 6.0不再支持 Apache HTTP client。 请使用 HttpURLConnection 代替。想要继续使用 Apache HTTP client 的,请添加如上代码。

posted in Swift 

ObjectMapper is a swift library like Gson in Java. Using ObjectMapper, I can easily convert basic classes into JSON format string or convert it inversely.

The code below shows how to convert swift array into JSON and also recover it from JSON.

class Book: Mappable{
    var id:Int?
    var title:String?
    var category:[String]?
    init(id:Int, title:String, category:[String]){ = id
        self.title = title
        self.category = category
    required init?(_ map: Map) {
    func mapping(map: Map) {
        id          <- map["id"]
        title       <- map["title"]
        category    <- map["category"]

// Do the conversion
let JSON = "{\"id\":3, \"title\":\"The Third Book\", \"category\":[\"TOP\", \"TECH\"]}"

// Convert JSON to class instance
let book3 = Mapper<Book>().map(JSON)!

let book1 = Book(id: 1, title: "The First Book", category: ["TECH"])
let book2 = Book(id: 2, title: "The Second Book", category: ["ART","MUSIC"])
let books = [book1, book2, book3]
// Convert array to JSON array string
let arrayJSON = Mapper().toJSONString(books, prettyPrint: true)

// Convert JSON array back to the array
let bookArray = Mapper<Book>().mapArray(arrayJSON)

TAG: ObjectMapper, JSON, Swift, Array, Convert, Conversion

posted in Swift  iOS 

The class NSDateFormatter is an easy-to-use tool. Just like SimpleDateFormat in Java.

Convert String to NSDate

let str = "2016-06-01T00:00:00Z"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let date = dateFormatter.dateFromString(str)

Convert NSDate to String

let description = "Time is \(dateFormatter.stringFromDate(date))"

TAG: Convert, String, NSDate, NSDateFormatter

posted in Java 

Integer 是 Java 5 引入的新特性,该特性能节省内存和改善性能。同样被引入缓存机制的还有 Byte,Short,Long,Character,缓存范围都是在 [-128,127] (Character是在[0,127])之间。

1. 对 Integer 对象引入了 IntegerCache 类,其他封装类型也有对应的 XxxCache。
2. 该缓存特性只有在 autoboxing 过程中使用,换言之,使用 constructor 创建的 Integer 并不能被缓存。
3. 因为缓存机制的存在,在缓存范围内的对象都来自同一个缓存。带来的副作用是使用“==”地址比较运算符比较两个看似不一样的对象,得到的是 true。网上其他文章的说法是因而可以使用 == 来比较直接比较两个对象的值。但我觉得这样理解容易造成偏差。Java 规范并没有约定 [-128,127] 的范围内 == 用作值比较,这只是一个副作用。
4. 只有 Integer 对象可以通过指定 JVM 启动参数来修改缓存上限。


简单地验证Java Integer缓存特性

import com.sun.istack.internal.NotNull;
 * Created by Lawrence on 15/11/9.
public class Main {
    public static void main(String[] argv){
        Integer int1 = 100;
        Integer int2 = 100;
            print("int1 is equal to int2");
        } else {
            print("int1 is not equal to int2");
        // prints "int1 is equal to int2"
        Integer int3 = 2333;
        Integer int4 = 2333;
            print("int3 is equal to int4");
        } else {
            print("int3 is not equal to int4");
        // prints "int3 is not equal to int4"
        Integer int5 = 100;
        Integer int6 = new Integer(100);
            print("int5 is equal to int6");
        } else {
            print("int5 is not equal to int6");
        // prints "int5 is not equal to int6"
    public static void print(String str){
posted in JavaScript 

这是由荷兰程序员 Gabor de Mooij 提出的一种比较简单的方法。Gabor de Mooij 称之为 minimalist approach。现摘录如下:

定义一个 Foo 类
var Foo = {
    createNew: function(){
        var instance = {};
        instance.description = "A new class instance"; = function() { console.log(instance.description)};
        return instance;
创建一个 Foo 实例
var foo = Foo.createNew();;
var NewFoo = {
    createNew = function(){
        var instance = Foo.createNew();
        instance.title = "A new title";
        instance.newBar = function(){
var Foo = {
    createNew: function(){
        var instance = {};
        instance.description = "A new class instance"; //description 是私有的,只有通过 bar() 来访问 = function() { console.log(instance.description)};
        return instance;
var Foo = {
    id: 101010; // id 在多个实例间共享
    createNew: function(){
        var instance = {};
        instance.description = "A new class instance"; //description 是私有的,只有通过 bar() 来访问 = function() { console.log(instance.description)};
        return instance;

var foo1 = Foo.createNew();
var foo2 = Foo.createNew(); = 233333;
console.log("Foo id:";

posted in Others 

A very little snippet of Gradle parallel task execution. Let taskes run concurrently.

gradle -Dorg.gradle.parallel.intra=true hello hello2 --parallel Add argument '-Dorg.gradle.parallel.intra=true' to enforce Gradle run taskes parallelly as for --parallel is an incubating feature,

class ParallelTask extends DefaultTask {
     String title = "Default Name"
     def action1() {
        for (int i=0 ;i < 5; ++i) {
            println 'The '+ title + " task is running"

task hello(type: ParallelTask)

hello {

task hello2(type: ParallelTask)

hello2 {


[1] Using ParallelizableTask
[2] Annotation Type ParallelizableTask
[4] Chapter 24. Multi-project Builds

TAG: Gradle, Parallel Execution, Task, Simultaneously, Concurrently, Synchronously

posted in JavaScript 

As for the reason only string can be stored in localStorage, an object need to be converted to string format (JSON text).

Save object

var books = [{id:3, name:"From Zero To One"}, {id:4, name:"Head First Java"}];
localStorage.setItem("books", JSON.stringify(books));

Load object

var booksJSON = localStorage.getItem("books");
if( booksJSON == null ){
    // No data stored in the localStorage
var books = JSON.parse(booksJSON);
for(var i=0; i < books.length; ++i) {
    var book = books[i];
    var id =;
    var name =;

posted in iOS 

Just set that:

button.imageView?.contentMode = .ScaleAspectFit

TAG: iOS, Xcode, UILabel, UIButton, image, icon, ScaleAspectFit, Adjust