2016年3月15日 星期二

promise javascript, wait when


        var waitJson

==========================================

            waitJson = new Promise(function(resolve, reject) {
                waitJson.resolve(json);
            });


==========================================
            Promise.all([waitJson]).then(function(values) {



            })
            .catch(function(error) {
              // One or more promises was rejected
              console.log(error)
              res.status(400).send(errors)
            });

2016年3月11日 星期五

angularjs select not updated , ng-option

This causes by ng-repeat , so use ng-option for instand

=================================
<select ng-model="selected">
 <option value="{{ value }}" ng-repeat="value in items" >{{ value }}</option>
</select>

=================================


<div ng-controller="Controller">
<select ng-options="item as item.label for item in items track by item.id" ng-model="selected">
<option value="" disabled selected>month</option>
</select>
</div>

=================================

<script>
angular.module('docsTemplateUrlDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.items = [{
 id: 1,
 label: 'aLabel',
 subItem: { name: 'aSubItem' }
}, {
 id: 2,
 label: 'bLabel',
 subItem: { name: 'bSubItem' }
}];

$scope.selected = "month";

}])
</script>

2016年3月9日 星期三

angular state resolve

Resolve
- to provide your controller with content or data that is custom to the state.
- promises, they will be resolved and converted to a value before the controller is instantiated and the $stateChangeSuccess event is fired.


The resolve property is a map object. The map object contains key/value pairs of: 
key – {string}: 
a name of a dependency to be injected into the controller.
factory - {string|function}: 
If string, then it is an alias for a service. Otherwise if function, then it is injected and the return value is treated as the dependency. If the result is a promise, it is resolved before the controller is instantiated and its value is injected into the controller.






Angular Expressions, evaluate

from: https://docs.angularjs.org/guide/expression
from: http://ng.malsup.com/#!/$parse-and-$eval
from: http://stackoverflow.com/questions/15671471/angular-js-how-does-eval-work-and-why-is-it-different-from-vanilla-eval
from: http://excellencenodejsblog.com/angularjs-compile-parse-interpolate/


result:






Q: What exactly is $eval doing? Why does it need its own mini parsing language?
Expressions are JavaScript-like code snippets that are usually placed in bindings such as {{ expression }}. Expressions are processed by $parse service.


Q: Why isn't plain old javascript "eval" being used?
If ... you do want to run arbitrary JavaScript code, you should make it a controller method and call the method. If you want to eval() an angular expression from JavaScript, use the $eval() method.

2016年3月8日 星期二

cron express ,

generator:
http://www.cronmaker.com/

from: http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger

六位的表達式 _ _ _ _ _ _
1 秒
2 分
3 小時
4 Day of month
5 月
6 Day of week


複雜例子 : or more complex, like this: 0/5 14,18,3-39,52 * ? JAN,MAR,SEP MON-FRI 2002-2010

* _ 都啟動 (例如用在分鐘,代表每一分鐘)
? _ 不指定 (例如指定10號,但不指定星期)
- _
, _ MON,WED,FRI
/ _ "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50".
L _ 在日期欄代表 這個月的最後一天/在星期欄代表這星期的最後一天(7或星期六)/
W _ 工作天(weekday)
# _ 這個月的第n個day (例如 "6#3" 在星期代表 月份的第3個星期五 ; 



ExpressionMeaning
0 0 12 * * ?Fire at 12pm (noon) every day
0 15 10 ? * *Fire at 10:15am every day
0 15 10 * * ?Fire at 10:15am every day
0 15 10 * * ? *Fire at 10:15am every day
0 15 10 * * ? 2005Fire at 10:15am every day during the year 2005
0 * 14 * * ?Fire every minute starting at 2pm and ending at 2:59pm, every day
0 0/5 14 * * ?Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day
0 0/5 14,18 * * ?Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day
0 0-5 14 * * ?Fire every minute starting at 2pm and ending at 2:05pm, every day
0 10,44 14 ? 3 WEDFire at 2:10pm and at 2:44pm every Wednesday in the month of March.
0 15 10 ? * MON-FRIFire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday
0 15 10 15 * ?Fire at 10:15am on the 15th day of every month
0 15 10 L * ?Fire at 10:15am on the last day of every month
0 15 10 ? * 6LFire at 10:15am on the last Friday of every month
0 15 10 ? * 6LFire at 10:15am on the last Friday of every month
0 15 10 ? * 6L 2002-2005Fire at 10:15am on every last friday of every month during the years 2002, 2003, 2004 and 2005
0 15 10 ? * 6#3Fire at 10:15am on the third Friday of every month
0 0 12 1/5 * ?Fire at 12pm (noon) every 5 days every month, starting on the first day of the month.
0 11 11 11 11 ?Fire every November 11th at 11:11am.

Error: Access to restricted URI denied

Error: Access to restricted URI denied, firefox, angular, http-server

Solution :
npm install -g http-server
vim index.html
http-server 

2016年3月7日 星期一

npm install problem, command not found


to get the default path:
npm config get prefix

 export PATH="/Users/username/npm/lib/node_modules/vue-cli/bin:$PATH"
$PATH="/Users/username/npm/lib/node_modules/vue-cli/bin:$PATH"

The default on OS X is /usr/local, which means that npm will symlink binaries into /usr/local/bin, which should already be on your PATH (especially if you're using Homebrew).




2016年3月3日 星期四

ajax, promise


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////  $.when(
 
    $.ajax({
      method: "GET",
      url: "https://api.leancloud.cn/1.1/classes/Building",
      headers: {
        "X-LC-Id": "key1",
        "X-LC-Key": "key2" ,
        "Content-Type": "application/json"
      },
      data: {}
    })

  ).then(function(msg1) {
    console.log( msg1 );

    return $.ajax({
      method: "GET",
      url: "https://api.leancloud.cn/1.1/classes/Building",
      headers: {
        "X-LC-Id": "key1",
        "X-LC-Key": "key2" ,
        "Content-Type": "application/json"
      },
      data: {}
    })

  }).then(function(msg2) {
    console.log( msg2 );
  });


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function createRoomAjax(roomName) {
  var deferred = $.Deferred();
    return $.ajax({
      type: "POST",
      url: "/createChatRoom",
      data: {chatroomId: roomName, chatroomName: roomName},
      success: function(xhr) {
        $("#clientToken").val(xhr);
        deferred.resolve(xhr);
      }
    });
  return deferred.promise();
}

$.when(
    createRoomAjax(randomChatroom),
    getClientTokenAjax(deviceName)
).done(function(d) {})

2016年3月2日 星期三

node js http request data send head


var optionsProduct = {
   url: 'url',
   method: 'GET',
   headers: {
       'X-LC-Id': 'key1',
       'X-LC-Key': 'key2',
       'Content-Type': 'application/json'
   },
   form: {'limit':'1000'}
}

2016年3月1日 星期二

node express, send http post request




app.get('/hello', function(req, res){

var options = {
   url: 'https://api.leancloud.cn/1.1/functions/fun1',
   method: 'POST',
   headers: {
       'X-LC-Id': 'key1',
       'X-LC-Key': 'key2',
       'Content-Type': 'application/json'
   }
};

function callback(error, response, body) {
 if (!error ) {
   var result = JSON.parse(JSON.parse(body).result);

   console.log("result");
   console.log(result);

   res.json(result)
 }
 else{
  console.log("error")
  console.log(error)
  console.log("response")
  console.log(response)
 }
}

request.post(options, callback);

    });