<repo_name>TieChi/tests<file_sep>/underscore/underscore.js
import _ from 'underscore';

let arr = [1,2,3,4,5,6];

// let a = _.map(arr, (num) => {
//     return a*2
// })
console.log(arr);<file_sep>/AngularJS-imooc/AngularJS实战第二章第五节指令源代码/app/$Directive&Directive/ex.js
let myModule = angular.module('MyModule',[]);
//公共的superman方法，
//	先定义了控制器中的所有方法
//	在定义link中的事件
myModule.directive("superman",function (){
	return {
		scope: {},
		restrict: 'ECMA',
		controller: function ($scope){
            $scope.abilities = [];
            this.addStrength = function() {
                $scope.abilities.push("strength");
            };
            this.addSpeed = function() {
                $scope.abilities.push("speed");
            };
            this.addLight = function() {
                $scope.abilities.push("light");
            };
		},
		link: function(scope, element, attrs) {
            element.bind("mouseenter", function() {
                console.log(scope.abilities);
            });
        }
	}
});
//在具体指令中引用公共指令，
//		并使用其定义的方法
myModule.directive('strength',function (){
	return {
		require: '^superman',
		link: function(scope, element, attrs, supermanCtrl) {
            supermanCtrl.addStrength();
        }
	}
});
myModule.directive('speed',function (){
	return {
		require: '^superman',
		link: function(scope, element, attrs, supermanCtrl) {
            supermanCtrl.addSpeed();
        }
	}
});
myModule.directive('light',function (){
	return {
		require: '^superman',
		link: function(scope, element, attrs, supermanCtrl) {
            supermanCtrl.addLight();
        }
	}
});

<file_sep>/Node.js/day2/05.js
let Person = require('./test/Person.js');

let person = new Person("小明");

person.sayHello();

<file_sep>/Node.js/album/models/file.js
let fs = require("fs")

exports.getUp = function (callback) {
    callback()
}

exports.getAllAlbum = function (callback) {
    fs.readdir("./upload", function (err, files) {
        var allAlbums = [];
        (function iterator(i){
            if (i === files.length) {
                callback(allAlbums)
                return
            }
            fs.stat("./upload/" + files[i], function (err, stats) {
                if ( stats.isDirectory() ) {
                    allAlbums.push(files[i])
                }
                iterator(i+1)
            })
        })(0);
    })
}

exports.getImagesByAlbumName = function (name, callback) {
    let list = fs.readdirSync("./upload/"+name)
    let allImages = []
    for (let i=0; i<list.length; i++) {
        let file = fs.statSync("./upload/" + name + '/' + list[i])
        if ( file.isFile() ) {
            allImages.push(list[i])
        }
    }

    callback(allImages)
}<file_sep>/Node-imooc/http/scope.js
let globalVariable = 'This is global variable';
<file_sep>/vue-imooc/vuex-1/src/router/index.js
import Vue from 'vue'
import Router from 'vue-router'
<<<<<<< HEAD
// import Vuex from 'Vuex'
import Hello from '@/components/Hello'

Vue.use(Router)
// Vue.use(Vuex)

// let store = new Vuex({
// })
=======

Vue.use(Router)
>>>>>>> eda3521920c2855a33d682ebac40e0c21532f2d6

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Hello',
      component: Hello
    }
  ]
})
<file_sep>/Node.js/day2/test/foo.js

let msg = "Hello World";

let showMsg = function () {
    console.log(msg);
}

exports.msg = msg;
exports.showMsg = showMsg;<file_sep>/1/D3-1/main.js

/*添加节点div，并向其中添加Hello World*/

let body = d3.select('body');
body.style("color","black").style("background-color","#fff");
/*创建div节点，并将它添加到body中*/
let div = body.append('div');
div.html('Hello World!');

/*选中所有的section节点，
向每一个section中添加节点和Hello World！*/

let section = d3.select('body').selectAll('section');
let divs = section.append('div');
divs.html('Hello World!');

<file_sep>/AngularJS-imooc/AngularJS实战第二章第四节路由源代码/app/ex3.js
var routerApp = angular.module('routerApp',['ui.router']);

routerApp.config(function ($stateProvider, $urlRouterProvider){
	$urlRouterProvider.otherwise('/index');

	$stateProvider
		.state('index',{
			url: '/index',
			views: {
				'': {
					templateUrl: 'tpls3/index.html'	
				},
				'topbar@index': {
					templateUrl: 'tpls3/topbar.html'
				},
				'main@index': {
					templateUrl: 'tpls3/home.html'
				}

			}
		})
		.state('index.usermng',{
			url: '/usermng',
			views: {
				'main@index': {
					templateUrl: 'tpls3/usermng.html',
					controller: function($scope, $state) {
                        $scope.addUserType = function() {
                            $state.go("index.usermng.addusertype");
                        }
                    }
				}
			}
		})
		.state('index.report',{
			url: '/report',
			views: {
				'main@index': {
					template: '<div>报告</div>'
				}
			}
		})
		.state('index.settings',{
			url: '/settings',
			views: {
				'main@index': {
					template: '<div>关于</div>'
				}
			}
		})
});<file_sep>/Node.js/day5/03.js
let express = require("express")
let formidable = require("formidable")
let app = express()
let db = require("./model/db.js")

app.set("view engine", "ejs")
app.use(express.static("./public"))

app.get("/", function(req, res, next) {
	res.render("index")
})
app.get("/find", function(req, res, next) {
	db.find("03", function (err, result) {
		res.json(result)
	})
})

app.post("/commit", function (req, res) {
	let form = new formidable.IncomingForm()
	form.parse(req, function(err, fields) {
		db.insertOne("03", {
			"name": fields.name,
			"message": fields.message
		}, 
		function (err, result) {
			if (err) {
				res.json("false")
				return
			}
			res.json("true")
		})
	})
})

app.listen(3000)<file_sep>/AngularJS-imooc/AngularJS实战第二章第五节指令源代码/app/$Directive&Controller/js.js
let myModule = angular.module('MyModule',[]);

myModule.directive('loader',function (){
	return {
		restrict: 'ECMA',
		link: function(scope,element,attr) {
			element.bind('mouseenter',function (event){
				scope.$apply(attr.howtoload);
			})
		}
	}
});

myModule.controller('MyCtrl',['$scope',function ($scope){
	$scope.loadData = function (){
		console.log('......');
	}
}]);
myModule.controller('MyCtrl2',['$scope',function ($scope){
	$scope.loadData = function (){
		console.log('。。。。。。');
	}
}]);<file_sep>/Node-imooc/http/callback.js
/*负责console的动作*/
function learn (something) {
    console.log(something);
}
/*负责调用回调函数和拼接字符串*/
function we (callback, something) {
    something += 'is cool';
    callback(something);
}
we (learn, 'Node.js');<file_sep>/AngularJS-imooc/AngularJS实战第二章第五节指令源代码/app/$templateCache/ex.js
var myModule = angular.module("MyModule", []);


myModule.run(function($templateCache) {
	$templateCache.put("hello.html","<div>!!!!!!!!!!!!</div>");
});

myModule.directive("hello", function($templateCache) {
	return {
		restrict: "ECMA",
		template: $templateCache.get("hello.html"),
		replace: true
	}
});<file_sep>/Node.js/day4/02/app.js
let datas = [
    {
        title: "No.0",
        content: "content<br>content<br>content<br>content"
    },
    {
        title: "No.1",
        content: "content<br>content<br>content<br>content"
    },
    {
        title: "No.2",
        content: "content<br>content<br>content<br>content"
    },
    {
        title: "No.3",
        content: "content<br>content<br>content<br>content"
    }
]

let express = require("express")
let app = express()

// app.set("view engine", "ejs")
app.use(express.static("./public"))
app.get("/news", function (req, res) {
    res.json(datas)
})

app.listen(3000)<file_sep>/Node.js/day1/08_fs.js
let http = require("http");
let fs = require("fs");

let server = http.createServer(function (req, res){
    if (req.url == "/favicon.ico") {
        return
    }
    let userId = parseInt(Math.random()*999999) + 1000;
    res.writeHead(200, {"Content-Type": "text/html;charset=UTF8"});
    fs.readFile("./text/1.txt", function(err,data){
        if (err) {
            throw err;
        }
        res.end(data);
    })
});

server.listen(4000, "127.0.0.1");<file_sep>/Node.js/day1/02_staticrender.js
let http = require("http");
let fs = require("fs");

let server = http.createServer(function (req, res) {
    if(req.url == '/square') {
        fs.readFile('./html/square.html', function(err, data) {
            res.writeHead(200, {"Content-type":"text/html;charset=utf-8"});
            res.end(data);
        });
    } else if (req.url == '/circle') {
        fs.readFile('./html/circle.html', function(err, data) {
            res.writeHead(200, {"Content-type":"text/html;charset=utf-8"});
            res.end(data);
        });
    } else if (req.url == '/jpg') {
        fs.readFile('./html/0.jpg', function(err, data) {
            res.writeHead(200, {"Content-type":"image/jpg"});
            res.end(data);
        });
    } else {
        res.writeHead(404, {"Content-type":"text/html;charset=utf-8"});
        res.end("NOT FOUND!!");
    }

});
server.listen(3000, "127.0.0.1");

//如果想修改结果，必须中断当前运行的服务器
//重启node，才能刷新结果。<file_sep>/Node.js/day2/12.js
var http = require("http");
var querystring = require("querystring");
var formidable = require('formidable');
var fs = require('fs');

var server = http.createServer(function(req,res){
    if (req.url == '/favicon.ico') {
        return;
    }
    if(req.url == "/doPost" && req.method.toLowerCase() == "post"){
        let form = new formidable.IncomingForm();
        form.uploadDir = "./dirs";

        form.parse(req, function (err, fields, files) {
            let oldPath = __dirname + '/' + files.upload.path;
            let newPath = __dirname + '/dirs/' + '123456' + '.jpg';
            console.log(oldPath);
            console.log(newPath);
            fs.rename(oldPath, newPath, function () {
                res.writeHead(200, {'Content-type': 'text/plain'});
                res.end('success');
            });
        });
    } else if (req.url == '/') {
        fs.readFile('./index.html', function (err, data) {
            if (err) {
                throw err;
            }
            res.writeHead(200, {'Content-type': 'text/html'});
            res.end(data);
        });
    }
});

server.listen(8080,"127.0.0.1");<file_sep>/Node.js/day2/14.js
let ejs = require('ejs');

let string = "今天买了iphone<%= a %>";

let data = {
    a: 'X'
}

let html = ejs.render(string, data);

console.log(html);<file_sep>/NodeInAction-code/exerise/ex3.2/index.js
let http = require('http');
let fs = require('fs');

http.createServer(function (req, res) {
    if(req.url == '/') {
        fs.readFile('./titles.json', function (err, data) {
            console.error(err);
            res.end('Server Error');
        });
    }
}).listen(8000, "127.0.0.1");<file_sep>/1/D3-2/main.js

/*添加节点div，并向其中添加Hello World*/

/*添加svg节点到#graph中，
并将svg命名为v*/
let v = d3.select("#graph")
			.append("svg");

v.attr("width",900).attr("height",400);


<file_sep>/vue-imooc/router-2/src/router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import Apple from '@/components/Apple'
import Banana from '@/components/Banana'
import red from '@/components/red'

Vue.use(Router)

let green = {
  template: '<div>THIS IS GREEN</div>'
}
let orange = {
  template: '<div>THIS IS ORANGE</div>'
}

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/Apple',
      name: 'Apple',
      component: Apple,
      children: [
        {
          path: 'red',
          component: red
        }
      ]
    },
    {
      path: '/Banana',
      name: 'Banana',
      component: Banana
    },
    {
      path: '/other',
      component: {
        view1: green,
        view2: orange
      }
    }
  ]
})
<file_sep>/Node.js/day1/09_fs.js
let http = require("http");
let fs = require("fs");

let server = http.createServer(function (req, res){
    if (req.url == "/favicon.ico") {
        return
    }
    let userId = parseInt(Math.random()*999999) + 1000;
    res.writeHead(200, {"Content-Type": "text/html;charset=UTF8"});
    fs.stat("./text", function (err, data){
        if (err) {
            throw err;
        }
        res.end("THIS IS IT");
        console.log(data.isDirectory())
    });
});

server.listen(4000, "127.0.0.1");<file_sep>/1/南丁格尔图/main.js
var echarts = require('echarts');

    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    // 绘制图表

    myChart.setOption({
        backgroundColor: '#232323',
        series: [{
            name: '访问来源',
            type: 'pie',
            radius: '55%',
            roseType: 'angle',
            itemStyle: {
                normal: {
                    shadowBlur: 200,
                    shadowOffsetX: 0,
                    shadowOffsetY: 0,
                    shadowColor: 'rgba(0,0,0,0.5)',
                    color: '#c23531'
                }
            },
            data: [
                {value:235,name:'视频广告'},
                {value:274,name:'联盟广告'},
                {value:310,name:'邮件营销'},
                {value:335,name:'邮件访问'},
                {value:400,name:'搜索引擎'}
            ],
            textStyle: {
                color: 'rgba(255, 255, 255, 0.3)'
            },
            label: {
                normal: {
                    textStyle: {
                        color: 'rgba(255,255,255,0.3)'
                    }
                }
            },
            labelLine: {
                normal: {
                    lineStyle: {
                        color: 'rgba(255,255,255,0.3)'
                    }
                }
            },
            visualMap: {
                // 不显示 visualMap 组件，只用于明暗度的映射
                show: false,
                // 映射的最小值为 80
                min: 80,
                // 映射的最大值为 600
                max: 600,
                inRange: {
                    // 明暗度的范围是 0 到 1
                    colorLightness: [0, 1]
                }
            }
        }]
        
    });
    <file_sep>/Node.js/day5/model/db.js
let MongoClient = require('mongodb').MongoClient

/*连接数据库的函数*/
/*在连接到mongodb后执行回调*/
function _connectDB(callback) {
	let url = 'mongodb://localhost:27017/dao'
	MongoClient.connect(url, function(err, db) {
		callback(err, db)
	})
}

/*在collection中添加一项的函数*/
exports.insertOne = function(collectionName, json, callback) {
	_connectDB(function (err, db) {
		/*在_connectDB（连接数据库）的回调函数中，添加增加一项的方法*/
		db.collection(collectionName).insertOne(json, function (err, rlt) {
			/*在添加一项的回调函数中，
			 *执行业务逻辑调用insertOne时的回调函数*/
			callback(err, rlt)
			db.close()
		})
	})
}

exports.find = function() {
	let collectionName = arguments[0]
	let args, callback
	if (arguments.length === 2) {
		args = { skip:0, limit:0 }
		callback = arguments[1]
	} else {
		args = arguments[1]
		callback = arguments[2]
	}

	_connectDB(function (err, db) {
		let cursor = db.collection(collectionName).find({}).skip(Number(args.skip)).limit(args.limit)
		let rlt = []
		cursor.each(function (err, doc) {
			if (err) {
				callback(err, null)
				return
			}
			if (doc !== null) {
				rlt.push(doc)
			} else {
				callback(null, rlt)
			}
		})
	})
}

exports.deleteMany = function(collectionName, json, callback) {
	_connectDB(function (err, db) {
		db.collection(collectionName).deleteMany(json, function (err, rlt) {
			callback(err, rlt)
			db.close()
		})
	})
}

exports.modMany = function(collectionName, preJson, modJson, callback) {
	_connectDB(function (err, db) {
		db.collection(collectionName).updateMany(preJson, modJson, function (err, result) {
			callback(err, result)
			db.close()
		})
	})
}<file_sep>/Node.js/day2/test/Person.js
function Person (name) {
    this.name = name;
}

Person.prototype = {
    sayHello: function () {
        console.log(this.name + ' : Hello,everyone.');
    }
}
module.exports = Person;<file_sep>/webpack-basic-usage/src/script/hello.js
var $ = require('jquery');
function hello() {
	// body...
}

// let body = $('body');
// console.log(body);<file_sep>/Node-imooc/crawler-promise.js
let http = require('http');
let Promise = require('Promise');
let cheerio = require('cheerio');
let baseUrl = 'http://www.imooc.com/learn';
let url = 'http://www.imooc.com/learn/637';

function filterChapters (html) {
    let $ = cheerio.load(html);
    let chapters = $('.mod-chapters').find('.chapter');
    let title = '';
    for (i=0; i<chapters.length; i++) {
        title += $(chapters[i]).find('.chapter-content').html();
    }
    console.log(title)
}

function getPageAsync () {
    return new Promise(function (resolve, reject) {
        console.log('crawling');

        http.get(url, function (res) {
        let html = '';
        res.on('data', function (data) {
            html += data;
        });
        res.on('end', function () {
            resolve(html)
            // filterChapters(html);
        })
        }).on('error', function() {
            reject(error);
            console.log('ERROR');
        });
    })
}

let fetchCourseArray = [];
videoIds.forEach( id => {
    fetchCourseArray.push(getPageAsync(baseUrl + id));
}); 

Promise
    .all(fetchCourseArray)
    .then(function (pages) {
        let courseData = [];

        pages.forEach(function (html) {
            
        });
    })



<file_sep>/Node.js/day1/07_router.js
let http = require('http');

let server = http.createServer(function (req, res) {
    let userurl = req.url;
    res.writeHead(200, {"Content-type":"text/html;charset-UTF8"});
    
    if (userurl.substr(0,9) == '/student/') {
        res.end("学生")
    } else if (userurl.substr(0,9) == '/teacher/') {
        res.end("教师")
    }
});

server.listen(3000, '127.0.0.1');<file_sep>/webpack-basic-usage/webpack.config.js
var htmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
	//js文件的输入和生成设置
	entry: {
		hello: './src/script/hello.js',
		a: './src/script/a.js',
		b: './src/script/b.js',
		c: './src/script/c.js'
	},
	output: {
		filename: './dist/js/[name].js'
	},
	//html文件的输入和生成设置
	plugins: [
		//插件功效：以某个html文件为模板更新创建首页内容
		//（体现为script标签的的动态引用和date数据的更新）
		new htmlWebpackPlugin({
			//html文件模板
			template: 'src/index.html',
			filename:"./dist/a.html",
			//注入信息的位置
			inject: 'head',
			//修改title和date数据信息
			title: 'a',
			//引用路径
			chunks: ['hello','a'],
			date: new Date()
		}),
		new htmlWebpackPlugin({
			template: 'src/index.html',
			filename:"./dist/b.html",
			inject: 'head',
			title: 'b',
			excludeChunks: ['a','c'],
			date: new Date()
		}),
		new htmlWebpackPlugin({
			template: 'src/c.html',
			filename:"./dist/c.html",
			inject: false,
			title: 'c',
			// excludeChunks: ['a','b'],
			date: new Date()
		})
	]
}<file_sep>/Node.js/day5/01.js
let express = require("express")
let app = express()
let MongoClient = require('mongodb').MongoClient
let assert = require('assert')

app.get("/", function(req, res){
	let url = 'mongodb://localhost:27017/01'
	MongoClient.connect(url, function(err, db) {
		if (err) {
			console.log('fail')
		}
		assert.equal(null, err);
		console.log('success')
		db.collection('rest').insertOne({
			"name": "haha",
			"age": Math.random()
		}, function(err, rlt) {
			console.log(rlt)
			db.close();
		})
	})
	res.send("Hello")
})

app.listen(3000)<file_sep>/Node-imooc/beginning/server.js
let http = require('http');
let server = http.createServer(function serverFun(req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('This is the fucking Hello World\n');
})
server.listen(1337, '127.0.0.1');

console.log('Running');<file_sep>/vue-imooc/1/src/main.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'

Vue.config.productionTip = false

let foreHead = {
  template: '<span>THIS IS FOREHEAD!!!</span>'
}
let hindBrain = {
  template: '<span>THIS IS HINDBRAIN!!!</span>'
}
let myHeader = {
  template: `<p>THIS IS MY HEADER!
               <br/><br/><br/><fore-head></fore-head>
               <br/><br/><br/><hind-brain></hind-brain>
             </p>`,
  components: {
    'fore-head': foreHead,
    'hind-brain': hindBrain
  }
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: {
    'my-header': myHeader
  }
})
<file_sep>/Node.js/day2/04.js
let foo = require("./test/foo.js");

console.log(foo.msg);

foo.showMsg();<file_sep>/Node.js/day2/03.js
let http = require("http");
let fs = require("fs");
let url = require("url");
let path = require("path");

let server = http.createServer(function(req, res){
    let pathname = url.parse(req.url).pathname;
    let fileUrl = '';
    if (pathname == '/favicon.ico') {
        return
    }
    if (pathname !== '/') {
        fileUrl = './'+path.normalize('static/'+ pathname);
    } else {
        fileUrl = './static/index.html';
    }

    let extName = path.extname(req.url);
    fs.readFile(fileUrl, function (err, data) {
        getMime(extName, function (mime) {
            res.writeHead(200, {"Content-Type": "text/html;charset=utf8"});
            res.end(data); 
        });
    });
});

server.listen(3000, '127.0.0.1');

function getMime (extName, callback) {
    let mime;
    fs.readFile("./mime.json", function (err, data) {
        if (err) throw Error("找不到相关文件");
        mimeObj = JSON.parse(data);
        let mime = mimeObj[extName] || 'text/plain';
        callback(mime);
    });
}<file_sep>/AngularJS-imooc/AngularJS实战第二章第四节路由源代码/app/ex.js
var routerApp = angular.module('routerApp',['ui.router']);

routerApp.config(function($stateProvider, $urlRouterProvider) {
	$urlRouterProvider.otherwise('/home');

	$stateProvider
		.state('home',{
			url: '/home',
			templateUrl: 'tpls2/home.html'
		})

		.state('about',{
			url: '/about',
			templateUrl: 'tpls2/about.html'
		})
});