Skip to content

Instantly share code, notes, and snippets.

View cheng470's full-sized avatar
🌴
On vacation

cheng470 cheng470

🌴
On vacation
View GitHub Profile
@cheng470
cheng470 / app.js
Last active August 29, 2015 14:08
express 框架的 hello world 例子
var express = require('express');
var app = express();
app.get('/hello.txt', function (req, res) {
res.send('Hello World');
});
var server = app.listen(3000);
// 浏览器访问 http://127.0.0.1:3000/hello.txt
@cheng470
cheng470 / module.js
Created November 7, 2014 08:40
模块规范
// 1 CommonJS 规范
// 定义
// math.js
exports.add = function () {
var sum = 0;
for (var i = 0, l = arguments.length; i < l; i++) {
sum += arguments[i];
}
return sum;
@cheng470
cheng470 / twister.html
Created November 4, 2014 15:42
用 canvas 绘制的一个旋转图案
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twister</title>
<style>
body { background: black }
canvas { margin: 0 auto; display: block; padding: 1px; }
</style>
</head>
@cheng470
cheng470 / emmet.html
Last active August 29, 2015 14:08
使用Emmet写一个完整的HTML5文档结构
<!--
!>#wrapper>(header>(#logo>img)+h1+nav>ul>li*3)+(#body>header>h2+p)+(footer>p)
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
@cheng470
cheng470 / bubbleSort.js
Created October 30, 2014 16:28
冒泡排序测试
/*
* 生成随机整数
* 范围为[0, 100)
*/
var generateNumber = function() {
return parseInt(Math.random() * 100, 10);
}
/*
@cheng470
cheng470 / regexpDemo.html
Created October 22, 2014 07:11
正则例子
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RegExp Validate Demo</title>
</head>
<body>
<input type="text" id="txt" name="txt" />
<input type="button" id="btn" value="Validate Email" />
<div id="print"></div>
@cheng470
cheng470 / browser-info.html
Created October 22, 2014 06:48
浏览器信息
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>userAgent</title>
</head>
<body>
<div id="print"></div>
<script>
var print = document.getElementById("print");
@cheng470
cheng470 / run.html
Created October 22, 2014 04:37
通过弹窗运行代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>run code</title>
</head>
<body>
<textarea name="txt" id="txt" cols="40" rows="10"></textarea>
<br />
<input type="button" id="btn" value="Run">
@cheng470
cheng470 / escapeHtml.js
Created October 22, 2014 00:25
为了保证页面输出安全,我们经常需要对一些特殊的字符进行转义,请写一个函数escapeHtml,将<, >, &, “进行转义
function escapeHtml(str) {
return str.replace(/[<>"&]/g, function(match) {
switch (match) {
case "<": return "&lt;";
case ">": return "&gt;";
case "&": return "&amp;";
case "\"": return "&quot;";
}
});
}