IntelliJ 14 Jetty integration

Categories: Development NotesJava November 30th, 2014 23:02

Bug with Jetty 9.2.5?

Tried Jetty jetty-distribution-9.2.5.v20141112 but got this Error when configuring the jetty server:
”start.d\http.ini not found”;

cannot find jetty.base when starting the sever:

WARNING: Missing Required File: ${jetty.base}\lib\alpn\alpn-boot-8.1.0.v20141016.jar

Use Jetty 8?

works fine with Jetty 8.

Functional Programming in JavaScript Notes (Array map & filter)

Categories: JavaScript; Tagged with: ; @ November 20th, 2014 23:35

Array.Map:

Array.prototype.map = function(projectionFunction) {
     var results = [];
     this.forEach(function(itemInArray) {

        // ------------ INSERT CODE HERE! ----------------------------
         // Apply the projectionFunction to each item in the array and add
         // each result to the results array.
         // Note: you can add items to an array with the push() method.
         // ------------ INSERT CODE HERE! ----------------------------
     results.push(projectionFunction(itemInArray));

    });

    return results;
};

// JSON.stringify([1,2,3].map(function(x) { return x + 1; })) === '[2,3,4]'

Array.filter

Array.prototype.filter = function(predicateFunction) {
     var results = [];
     this.forEach(function(itemInArray) {
         // ------------ INSERT CODE HERE! ----------------------------
         // Apply the predicateFunction to each item in the array. If the
         // result is truthy, add each result to the results array.
         // Note: remember you can add items to the array using the array's
         // push() method.
         // ------------ INSERT CODE HERE! ----------------------------
     if(predicateFunction(itemInArray)) {
        results.push(itemInArray);
     }
     });

    return results;
};

// JSON.stringify([1,2,3].filter(function(x) { return x > 2})) === "[3]"

Chaining call

function() {
     var newReleases = [
             {
                 "id": 70111470,
                 "title": "Die Hard",
                 "boxart": "http://cdn-0.nflximg.com/images/2891/DieHard.jpg",
                 "uri": "http://api.netflix.com/catalog/titles/movies/70111470",
                 "rating": 4.0,
                 "bookmark": []
             },
             {
                 "id": 654356453,
                 "title": "Bad Boys",
                 "boxart": "http://cdn-0.nflximg.com/images/2891/BadBoys.jpg",
                 "uri": "http://api.netflix.com/catalog/titles/movies/70111470",
                 "rating": 5.0,
                 "bookmark": [{ id:432534, time:65876586 }]
             },
             {
                 "id": 65432445,
                 "title": "The Chamber",
                 "boxart": "http://cdn-0.nflximg.com/images/2891/TheChamber.jpg",
                 "uri": "http://api.netflix.com/catalog/titles/movies/70111470",
                 "rating": 4.0,
                 "bookmark": []
             },
             {
                 "id": 675465,
                 "title": "Fracture",
                 "boxart": "http://cdn-0.nflximg.com/images/2891/Fracture.jpg",
                 "uri": "http://api.netflix.com/catalog/titles/movies/70111470",
                 "rating": 5.0,
                 "bookmark": [{ id:432534, time:65876586 }]
             }
         ];

    // ------------   INSERT CODE HERE!  -----------------------------------
     // Chain the filter and map functions to select the id of all videos
     // with a rating of 5.0.

    return newReleases.
         filter(function(video) {
             return video.rating === 5.0;
         }).
         map(function(video) {
             return video.id;
         });
     // ------------   INSERT CODE HERE!  -----------------------------------
}

JavaScript Day1: Java Script Objects

Categories: JavaScript; Tagged with: ; @ November 13th, 2014 22:57
  // define a flight
        var flight = {
            airline: "KLM",
            number: 835,
            departure: {
                city: "SG",
                IATA: "SIN"
            },
            scheduleDays: [1, 2, 5]
        };

        console.log("Flight: ", flight);

        // add new attribute
        flight.code="KLM835";
        console.log("Added code: ", flight);

        // retrieve attribute
        console.log("Retrieve departure city:", flight.departure.city);

        // delete attribute
        console.log("Flight code: ", flight.code);
        delete flight.code;
        console.log("Deleted flight code: ", flight.code);

        // for...in
        for(day in flight.scheduleDays) {
            console.log("for...in: schedule day: ", day);
        }

        // for loop
        for(i = 0; i < flight.scheduleDays.length; i++ ) {
            console.log("Schedule day:", flight.scheduleDays[i], " @ index: " , i);
        }

        // define new function
        var printFlight = function(flight) {
         return "Flight print: " +  flight.airline + " - " + flight.number;
        };

        // initialize new flight via prototype;
        var flight2 = Object.create(flight);
        console.log("Flight2 created based on Flight: " +  printFlight(flight2));

        // add new attribute to the new flight
        flight2.code = "KML836";
        console.log("Flight2.code: ", flight2.code);
        console.log("Flight.code: ", flight.code);

        // update new flight
        flight2.airline = "SIA";
        console.log("Flight.airline: ", flight.airline);
        console.log("Flight2 airline", flight2.airline);

        // update the prototype;
        flight.airline = "BA";
        console.log("Flight.airline: ", flight.airline);
        console.log("Flight2 airline", flight2.airline);

        // type of
        console.log(typeof flight);
        console.log(typeof flight2);
        console.log(typeof flight.scheduleDays[0]);

output:

Flight: 
Object {airline: "KLM", number: 835, departure: Object, scheduleDays: Array[3]}
Added code: 
Object {airline: "KLM", number: 835, departure: Object, scheduleDays: Array[3], code: "KLM835"}
Retrieve departure city: SG
Flight code:  KLM835
Deleted flight code:  undefined for...in: schedule day:  0 for...in: schedule day:  1 for...in: schedule day:  2 Schedule day: 1  @ index:  0 Schedule day: 2  @ index:  1 Schedule day: 5  @ index:  2 Flight2 created based on Flight: Flight print: KLM - 835
Flight2.code:  KML836 Flight.code:  undefined
flight.airline:  KLM Flight2 airline SIA Flight.airline:  BA
Flight2 airline SIA object object number

Java: Config slf4j and log4j in Maven Project

Categories: Java November 10th, 2014 23:29

1. Config Maven dependences


    <dependency>         <groupId>org.slf4j</groupId>         <artifactId>slf4j-api</artifactId>         <version>1.7.7</version>     </dependency>
      <dependency>        <groupId>org.slf4j</groupId>        <artifactId>slf4j-log4j12</artifactId>
       <version>1.7.7</version>
    </dependency>

2. Setup log4j configuration

src/main/resources/log4j.xml (log4j.properties):

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
   <appender name="console" class="org.apache.log4j.ConsoleAppender">
     <param name="Target" value="System.out"/>
     <layout class="org.apache.log4j.PatternLayout">
       <param name="ConversionPattern" value="%d %-5p %c{1} - %m%n"/>
     </layout>
   </appender>

  <root>
     <priority value ="debug" />
     <appender-ref ref="console" />
   </root>
</log4j:configuration>

or log4j.properties

log4j.rootLogger=DEBUG, STDOUT
log4j.logger.deng=INFO
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n

3. Initialize Logger and use it

package com.liguoliang.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogTest {

	static Logger LOGGER = LoggerFactory.getLogger(LogTest.class);
	
	public static void main(String[] args) {
		LOGGER.info("slf4j test info");
	}
}

output:

2014-11-10 23:07:39,624 INFO  LogTest - slf4j test info

Categories: 垃圾山 November 8th, 2014 15:52

日历上写着 winter begins,我猜是立冬了。

如果一年有四季,我最喜欢的是秋天。立冬意味着秋天即将结束,很快就要北风吹,雪花飘。我照旧忙碌在赤道附近绵绵无绝期的夏天里。 而我的家乡夏热冬凉,四季分明。

上次回家是在八月初,湿热的夏天, 晃悠了两周后,我开始盘算着什么时候回家找工作 买房子 娶媳妇这档子非办不可、皆大欢喜的事情。 飞机落地后纠结了几个小时,一觉睡过去,我决定继续随波逐流爱咋咋地。
紧接着去移民局拿了PR卡片。于是多了一个选择,但选择跟爱一样,都能可是潜在的痛苦。

但我还是喜欢秋天,清澈 凌烈 饱满 含蓄。冷气充足的办公室跟窗外飘摇的小树满足了我很多的幻想。这样的幻想让我短暂的活在虚构的季节里。 短短一生,不过几十个秋。

她说,你怎么还不更新?我说我跟你沉浸在生活里,没法探出头来看生活,没时间享受空虚寂寞,怎么能有空无病呻吟故做愁呢。
如果我会画画,一定要画一幅这样的照片,两人坐在秋天的午后,阳光透过所剩不多的树叶撒在身上,小风吹在背后,一地金黄的落叶跟着跑,两人安静的坐着,一言不发。

Newer Posts <-> Older Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.