Skip to content

Instantly share code, notes, and snippets.

View tsq's full-sized avatar
🏠
Working from home

TANG SHI QIANG tsq

🏠
Working from home
View GitHub Profile
@tsq
tsq / demo01
Created May 23, 2014 03:20
a demo
Statistics.query(paramForCash, function(result){
if (result.length) {
$scope.cash = {
cash: (result[0].value.cash/100).toFixed(2),
weixin: (result[0].value.weixin/100).toFixed(2)
};
}
});
@tsq
tsq / index.html
Created September 2, 2014 06:45
baiduMusic测试代码
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="jquery.min.js"></script>
<script>
var request = require("request");
var fs = require("fs");
var cheerio = require('cheerio');
var url = '';
request(url, function (err, res, body) {
if (err) {
return console.log(err);
}
@tsq
tsq / test.js
Created April 24, 2015 08:01
year + month + date + hour + miniute
function getTime() {
var date = new Date();
var year = date.getFullYear();
var month = (date.getMonth() + 1);
month = (month < 9) ? '0' + month : month;
var day = date.getDate();
day = (day < 9) ? '0' + day : day;
var hour = date.getHours();
hour = (hour < 9) ? '0' + hour : hour;
@tsq
tsq / test.js
Created April 30, 2015 15:20
random animation
function animation() {
var timeArr = (function () {
var speeds = [100];
for (var i = 200; i < 1500; i+=100) {
speeds.push(i);
}
return speeds;
})();
var animationsArr = [
'zoom-right',
@tsq
tsq / gulpfile.js
Created May 7, 2015 08:42
simple livereload
var gulp = require('gulp');
var gutil = require('gulp-util');
var express = require('express');
var path = require('path');
var tinylr = require('tiny-lr');
var createServers = function(port, lrport) {
var lr = tinylr();
lr.listen(lrport, function() {
gutil.log('LR Listening on', lrport);
@tsq
tsq / random.js
Created May 8, 2015 03:15
generate random number
// 1. 使用内置的随机数发生方法
Math.random(); // 该方法产生一个0到1之间的浮点数
Math.floor(Math.random() * 10 + 1); // 1-10
Math.floor(Math.random() * 24); // 0-23
// 2. 基于时间,亦可以产生随机数
var now = new Date();
var number = now.getSeconds(); // 这将产生一个基于目前时间的0到59的整数
var now = new Date();
@tsq
tsq / app.js
Created May 18, 2015 01:51
whether a module or a server
/**
*
* Created by tommytang on 5/18/15.
*/
var express = require("express");
var http = require("http");
var app = express();
var server = http.createServer(app);
@tsq
tsq / mvc.txt
Created May 18, 2015 02:00
More advanced applications might have a nested folder structure similar to this
├── app.js
├── package.json
├── views
└── *.jade
├── routes
└── *.js
├── models
└── *.js
├── config
@tsq
tsq / download
Last active August 29, 2015 14:23
download by nodejs
app.get('/download', function (req, res) {
var param = req.query['filename'];
if (!param) { return res.sendStatus(401);}
var file = __dirname + '/public/' + req.query['filename'];
if (!fs.existsSync(file)) {return res.sendStatus(404);}
var filename = path.basename(file);
var mimetype = mime.lookup(file);
res.setHeader('Content-disposition', 'attachment; filename=' + filename);
res.setHeader('Content-type', mimetype);