2016年2月26日 星期五

eb, aws, install, error

from:https://forums.aws.amazon.com/thread.jspa?threadID=164348



Make a virtual environment for the EB CLI:

sudo pip install virtualenv
cd ~
virtualenv eb-env

Activate the virtualenv and install awsebcli:
pip install awsebcli

Check that eb now works: 
eb --version

Deactivate and add eb to your path:
deactivate
source ~/eb-env/bin/eb




Error

Traceback (most recent call last):
  File "/usr/local/bin/eb", line 5, in <module>
    from pkg_resources import load_entry_point
  File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 3141, in <module>
  File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 3127, in _call_aside
  File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 3154, in _initialize_master_working_set
  File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 640, in _build_master
  File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 941, in require
  File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 828, in resolve



2016年2月22日 星期一

nodejs promise Q, Bluebird , async

bluebird

Async is a library for managing asynchronous operations that is not based on the use or design of promises.

================  1  file write nest ===============

fs.writeFile('./'+foldername+'/'+plist.filename, generatePlistContect(plist), function (err) {
   if (err)
       return console.log(err);
   console.log('Hello World > helloworld.txt');


fs.writeFile('./'+foldername+'/'+html.filename, generateHtmlContect(html), function (err) {
   if (err)
       return console.log(err);
   console.log('Hello World > helloworld2.txt');

console.log('going to index');
res.render('index', { title: foldername+" is created in basic" });
});
});


================  2  file write promise ===============

var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs"));

fs.writeFileAsync('./'+foldername+'/'+plist.filename, generatePlistContect(plist))
.then(function(){
        return fs.writeFileAsync('./'+foldername+'/'+html.filename, generateHtmlContect(html))
    }).then(function(){
    res.render('index', { title: foldername+" is created in promise" });
    }).catch(function(error){
    res.render('index', { title: error });
});
================  3  file write parallel ===============
var Promise = require("bluebird");
var fs = Promise.promisifyAll(require("fs"));

var pro = [];

pro.push(fs.writeFileAsync('./'+foldername+'/'+plist.filename, generatePlistContect(plist)))
pro.push(fs.writeFileAsync('./'+foldername+'/'+html.filename, generateHtmlContect(html)))

Promise.all(pro).then(function() {
     res.render('index', { title: foldername+" is created in promise_parallel" });
}).catch(function(error){
     res.render('index', { title: error });
});



Cannot install applications because the certificate is not valid

Cannot install applications because the certificate is not valid


http://xxx/abc.plist

->

https://xxx/abc.plist

平台 research


Kontena 

Kontena is an open-source system for deploying, managing, scaling and monitoring containerized applications across multiple hosts on any cloud infrastructure.


2016年2月21日 星期日

web socket

Differences between socket.io and web sockets



// ============== /node/app.js  ============
var server = require('http').createServer(app);

var io = require('socket.io').listen(server);


io.on('connection', function(client){
    console.log('Client connected...');

    client.on('join', function(data) {
        console.log(data);
        client.emit('messages', 'Hello from server');
    });

    client.on('messages', function(data) {
          console.log("here message");
          console.log("data: "+data);
           client.emit('broad', data);
           client.broadcast.emit('broad',data);
    });

});


server.listen(3001);
// ==========================================




// ==============  client side.html  ============

         <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        <script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>


        <form id="form" id="chat_form">
            <input id="chat_input" type="text">
            <input type="submit" value="Send">
        </form>


<script>
   var socket = io.connect('http://localhost:3001');
   socket.on('connect', function(data) {
       socket.emit('join', 'Hello World from client');
   });

       socket.on('messages', function(data) {
               alert(data);
       });

       socket.on('broad', function(data) {
               console.log("broad: "+data);
       });

$('form').submit(function(e){

console.log("form submit22222");
    e.preventDefault();
    var message = $('#chat_input').val();
    socket.emit('messages', message);
console.log("form submit33333 :"+message);
});
</script>

// ==========================================

2016年2月19日 星期五

css animation keyframe fade in


.svg-wrapper {
    -webkit-animation: fadein 2s; /* Safari and Chrome */
}

@-webkit-keyframes fadein { /* Safari and Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}




<div class="svg-wrapper">
   <div class="text">HOVER</div>
</div>

css animation keyframe

from: http://www.w3schools.com/cssref/css3_pr_animation-keyframes.asp

CSS Syntax

@keyframes animationname {keyframes-selector {css-styles;}}

Property Values

ValueDescription
animationnameRequired. Defines the name of the animation.
keyframes-selectorRequired. Percentage of the animation duration.
Legal values:
0-100%
from (same as 0%)
to (same as 100%)
Note: You can have many keyframes-selectors in one animation.
css-stylesRequired. One or more legal CSS style properties





把 animation 設定檔放到 css 內
 forward, backward, infinite
div {
    width: 100px;
    height: 100px;
    background: red;
    position :relative;
    -webkit-animation: mymove 5s forwards; /* Chrome, Safari, Opera */ 
    animation: mymove 5s forwards;
}

keyframe 設定檔
/* Chrome, Safari, Opera */ 
@-webkit-keyframes mymove {
    0%   {top: 0px;}
    25%  {top: 200px;}
    75%  {top: 50px}
    100% {top: 100px;}
}

/* Standard syntax */
@keyframes mymove {
    0%   {top: 0px;}
    25%  {top: 200px;}
    75%  {top: 50px}
    100% {top: 100px;}
}




angularjs image fade in , change

from: http://stackoverflow.com/questions/25719408/angularjs-animate-image-on-src-change




accepted
Thanks for the responses -
I ended up doing this, and it works ;)
--- Directive ---
.directive('fadeIn', function($timeout){
    return {
        restrict: 'A',
        link: function($scope, $element, attrs){
            $element.addClass("ng-hide-remove");
            $element.on('load', function() {
                $element.addClass("ng-hide-add");
            });
        }
    }
})
--- Template ---
<img src="{{program.image}}" class="animate-show" fade-in />
--- CSS ---
.animate-show.ng-hide-add, .animate-show.ng-hide-remove {
    transition: all linear 0.5s;
    display: block !important;
}

.animate-show.ng-hide-add.ng-hide-add-active, .animate-show.ng-hide-remove {
    opacity: 0;
}

.animate-show.ng-hide-add, .animate-show.ng-hide-remove.ng-hide-remove-active {
    opacity: 1;
}

2016年2月16日 星期二

vue - component inside component






Peter2.vue


PeterInput.vue

express, angularjs, jsnop



/************************/
/****   back end express   ***/
/************************/

router.get('/download', function(req, res) {
  var filename ="";

  if(req.query.type =="interior"){
    filename="right_interior_design.json"
  }
  else if(req.query.type =="brand"){
    filename="right_brand.json"
  }
  else if(req.query.type =="category"){
    filename="right_category.json"
  }
  else if(req.query.type =="type"){
    filename="right_interior_design_type.json"
  }
  else if(req.query.type =="space"){
    filename="right_space.json"
  }
  else if(req.query.type =="product"){
    filename="right_product.json"
  }
  else{
    res.send("file not found");
  }

  var filepath = '/home/sig/Archive/' + filename;

  // Tricky: do not awaiting for `downloadFileFromAcerCloud` async  :)
  downloadFileFromAcerCloud(filename);
  fs.readFile(filepath, 'utf8', function(err, data) {
    if (err) {
      res.send(err);
    } else {
      res.header("Access-Control-Allow-Origin", "*");
      res.json(JSON.parse(data));
    }
  });

})




/************************/
/****   front end angular   ***/
/************************/

angular.module('FilterInControllerModule', [])
.controller('Controller', function($scope, $http){

    $scope.result


    $http.get("http://113.196.236.128:5571/download?type=product").then(
        function(resp){
            console.log("success");
            console.log(resp.data);
            // $scope.result=resp.data.results;
            $scope.result=resp.data;
        },
        function(error){
            console.log("error");
            $scope.result=error;
        }
    );
/************************/
});

2016年2月14日 星期日

2016.2.14 - bayesian, Principle of maximum entropy


Principle of maximum entropy
-熵定义的实际上是一个随机变量的不确定性,熵最大的时候,说明随机变量最不确定,换句话说,也就是随机变量最随机,对其行为做准确预测最困难。

-熵原理本质上仅是“高概率的事物容易出现”


Why maximum entropy

例如,我们只知道一个班的学生考试成绩有三个分数档:80分、90分、100分,且已知平均成绩为90分。显然在这种情况下,三种分数档的概率分布并不是唯一的。因为在下列已知条件限制下
(平均成绩)
(概率归一化条件)
有无限多组解,该选哪一组解呢?即如何从这些相容的分布中挑选出“最佳的”、“最合理”的分布来呢?这个挑选标准就是最大信息熵原理。


Neville's algorithm

 p_{0,0}(x) = y_0 \,
 p_{0,1}(x) \,
 p_{1,1}(x) = y_1 \,  p_{0,2}(x) \,
 p_{1,2}(x) \,  p_{0,3}(x) \,
 p_{2,2}(x) = y_2 \,  p_{1,3}(x) \,  p_{0,4}(x) \,
 p_{2,3}(x) \,  p_{1,4}(x) \,
 p_{3,3}(x) = y_3 \,  p_{2,4}(x) \,
 p_{3,4}(x) \,
 p_{4,4}(x) = y_4 \,




Lagrange multiplier

a good tool to find maximum entropy 
is a strategy for finding the local maxima and minima of a function subject to equality constraints.
For instance (see Figure 1), consider the optimization problem
maximize f(xy)
subject to g(xy) = 0.
We need both f and g to have continuous first partial derivatives. We introduce a new variable (λ) called a Lagrange multiplier and study the Lagrange function (or Lagrangian) defined by
 \mathcal{L}(x,y,\lambda) = f(x,y) - \lambda \cdot g(x,y),


  • Probability axioms

    These assumptions can be summarised as follows: Let (Ω, F, P) be a measure space with P(Ω)=1. Then (Ω, F, P) is a probability space, with sample space Ω, event space F and probability measure P.

    第一公理[編輯]

    對於任意一個集合E\in \mathfrak{F}, 即對於任意的事件P(E)\in [0,1]
    即,任一事件的機率都可以用01區間上的一個實數來表示。

    第二公理[編輯]

    P(\Omega) = 1
    即,整體樣本集合中的某個基本事件發生的機率為1。更加明確地說,在樣本集合之外已經不存在基本事件了。
    這在一些錯誤的機率計算中經常被小看;如果你不能準確地定義整個樣本集合,那麼任意子集的機率也不可能被定義。

    第三公理[編輯]

    任意兩兩不相交事件E_1, E_2, ...可數序列滿足P(E_1 \cup E_2 \cup \cdots) = \sum P(E_i)
    即,不相交子集的並的事件集合的機率為那些子集的機率的和。這也被稱為是σ可加性。如果存在子集間的重疊,這一關係不成立。
    如想通過代數了解柯爾莫果洛夫的方法,請參照隨機變量代數

    從柯爾莫果洛夫公理可以推導出另外一些對計算機率有用的法則。
    P(A \cup B) = P(A) + P(B) - P(A \cap B)
    P(\Omega - E) = 1 - P(E)
    P(A \cap B) = P(A) \cdot P(B \vert A)
    這一關係給出了貝葉斯定理。以此可以得出A和B是獨立的若且唯若
    P(A \cap B) = P(A) \cdot P(B)


     Explain why

    假如我錯過了看世界盃,賽後我問一個知道比賽結果的觀眾哪支球隊是冠軍? 他不願意直接告訴我, 而要讓我猜,並且我每猜一次,他就要收一元錢才肯告訴我是否猜對了,那麼我需要付給他多少錢才能知道誰是冠軍呢
    我可以把球隊編上號,從 1  32, 然後提問: “冠軍的球隊在 1-16 號中嗎?” 假如他告訴我猜對了, 我會接著問: “冠軍在 1-8 號中嗎?” 假如他告訴我猜錯了, 我自然知道冠軍隊在 9-16 中。 這樣只需要猜五次, 我就能知道哪支球隊是冠軍。所以,誰是世界盃冠軍這條消息的信息量只值五塊錢
    當然,香農不是用錢,而是用 bit的個概念來度量信息量。 一個bit是一位元二進位數字,電腦的一個位元組(byte)是八個bit。
    上面的例子中,這條消息的信息量是五 bit。如果有六十四個隊進入決賽,那麼誰世界盃冠軍的信息量就會是6個 bit。到此我們可以發現:原來
    香農的信息量( bit數)來自:所有可能結果的 log 函數log32=5, log64=6