2015年7月28日 星期二

Moodle on Cloud

Moodle on Google Compute Engine

Installing moodle on Heroku

deploying wabapps (e.g. moodle) on heroku

Moodle site on heroku with amazon s3

a build pack bundling PHP and Apache for Heroku apps

How to Moodle

2015年7月14日 星期二

Mongoose



var mongoose = require('mongoose');
// 連線到localhost上的MongoDB,使用test資料庫
mongoose.connect('mongodb://localhost/test');

// 定義存取Cat資料表的模式,定義一個欄位name,是字串態別
var Cat = mongoose.model('Cat', {
    name: String,
    age: Number
});

// 建立一筆貓的新資料,name欄位是Zildjian
var kitty = new Cat({ name: 'Zildjian', age: 10 });

// 存入該資料到MongoDB
kitty.save(function (err) {

    if (err) {
        // 存入失敗
        console.log('Something\'s wrong');
        return;
    }

    // 存入成功
    console.log('meow');
});

var kitty = new Cat();
kitty.name = 'Kitty';
kitty.age = 5;
kitty.save();

Cat.find(function(err, cats) {

    for (var index in cats) {
        var cat = cats[index];

        console.log(cat.name);
    }
});

Cat.find({ name: 'kitty' }, function(err, cats) {

    for (var index in cats) {
        var cat = cats[index];

        console.log(cat.name);
    }
});

// 尋找age大於等於5的資料
Cat.find({ age: { $gte: 5 } }, function(err, cats) {
    // Do stuffs
});

// 尋找name裡面包含kitty字串的資料
Cat.find({ name: /kitty/i }, function(err, cats) {
    // Do stuffs
});

Cat.remove({ name: 'Zildjian' }, function(err) {
    if (err)
        console.log('刪除失敗');
    else
        console.log('刪除成功');
});

// 尋找nameZildjian的資料,然後修改成Blue,並且把age改成11
Cat.update({ name: 'Zildjian' }, { name: 'Blue', age: 11 }, function(err) {
    if (err)
        console.log('修改失敗');
    else
        console.log('刪除成功');
});

Cat.update({ name: 'Zildjian' }, { $set: { age: 11 } }, function(err) {
    if (err)
        console.log('修改特定欄位失敗');
    else
        console.log('刪除特定欄位成功');
});


Node-webkit : 用 HTML+JavaScript 撰寫「視窗程式」的好工具

http://www.codedata.com.tw/javascript/node-webkit-great-tool-for-gui/

2015年7月9日 星期四

MongoDB

1. install Node.js
2. install MongoDB
3. mk dir C:\data\db, 這是 MongoDB 預設的資料庫檔案存放位置,如果想指定別的路徑,可以將啟動的指令 mongod 改為 mongod --dbpath <路徑位置>。

4. cd C:\Program Files\MongoDB\Server\3.0\bin
5. C:\Program Files\MongoDB\Server\3.0\bin>mongod
    (launch MongoDB server)

6. C:\Program Files\MongoDB\Server\3.0\bin>mongo
    (launch MongoDB comand line interface)

7. >use CatS
8. >kitty = {name: "Hellow Kitty", age:2};
9. >db.CatS.save(kitty);
    (Please check c:\data\db to see something related to CatS)

10. >db.CatS.find();

11. How to querry 查詢:
      >db.CatS.findOne({name: "Hellow Kitty"});

12. How to update 更改資料:
      >var updateFood = db.CatS.findOne({name: "Hellow Kitty"});
      >updateFood.food = "fish";
      >db.CatS.save(updateFood);
      >db.CatS.findOne({name: "Hellow Kitty"});

13. 循環寫入資料:
      >for (var i =1; i <= 5; i++) db.CatS.save({index : i, count : i - 1});
      >db.CatS.find();    //會看到有六筆資料

14. How to delete  刪除:
      >db.CatS.findOne({index:2});
      >db.CatS.remove({index:2});
      >db.CatS.find();   //哪一筆資料被刪除了呢?

15. 進階查詢資料, forEach() 循環遍歷 方法:
      >db.CatS.find().forEach(printjson);

16. 進階查詢資料, 直接使用 array 陣列:
     >var soManyCats = db.CatS.find();
     >printjson(soManyCats[3]);

     >var catsArray = db.CatS.find().toArray();
     >catsArray[4];