Skip to content

Instantly share code, notes, and snippets.

@wiky
wiky / querystring.js
Last active December 17, 2015 21:09
provides utilities for dealing with query strings.
(function(exports) {
var defaults = {
sep: '&',
eq: '=',
// 把querystring中的值仅按字符串解析
// 值为true时,如arr=[1,2] -> {"arr": "[1,2]"}
beString: false
};
var querystring = {
// 'str="aaa"&bool&num=123&arr=[1,2]&obj={"foo":1}'
@wiky
wiky / route.js
Last active December 19, 2015 10:58
url parser
// 匹配路由字符串参数的正则表达式。
var optionalParam = /\((.*?)\)/g;
var namedParam = /(\(\?)?(:\w+)(?:\\\[([^\]]+)\\\])?/g;
var itemParam = /:(\w+)(\?)?(?:\[([^\]]+)\])?/g;
var splatParam = /\*/g;
var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
/**
* 路由规则转为正则表达式
*
@wiky
wiky / tmpl-demo.html
Last active April 18, 2017 08:00
template lite
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<style>
body{background-color:#f4f4f4;color:#555;width:80%;padding:20px;font-size:16px;font-weight:200;margin:0 auto;font-family:Helvetica Neue,arial,verdana}h1{color:#708090;text-shadow:0 1px 2px #fff;font-size:4em;text-align:center}.subtitle{text-align:center;margin-bottom:60px}h2{text-shadow:0 1px 2px #fff}h2 span{font-weight:200;font-size:14px}a{color:#a80000}.smaller{font-size:.8em}h4{margin:4px 0;font-weight:400;font-size:20px}textarea{font-family: Arial;border:1px solid lightgrey;outline:none;font-size:14px;width:96%;height:310px;font-size: 20px;padding:10px;text-align:left}.templategroup,.datagroup,.functiongroup,.resultgroup{width:48%;margin:4px 2% 4px 0;float:left;min-width:300px;}.function,.result{background:#DDD;height:312px;font-size: 20px;padding:10px;font-size:14px;overflow-y:auto}.definegroup{display:none}.templategroup.withdefs .definegroup{display:block}.temp
@wiky
wiky / index.html
Last active December 20, 2015 15:29
slide
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Odin</title>
<link href="style.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="slide.js"></script>
<script>
$(function(){
@wiky
wiky / uuid.js
Last active December 22, 2015 10:58
uuid
function uuid() {
return (Math.random()).toString(36).slice(2, 7);
}
(function() {
var cache = {};
this.tmpl = function(str, data) {
cache[str] = cache[str] ||
new Function('data', [
'var _p="";\nwith(arguments[0]||{}){\n_p+="',
str.replace(/"/g, '\\$&')
.replace(/[\r\n]/g, '')
.replace(/<%([^\w\s\}\)]*)\s*(.*?)\s*%>/g, function(match, mark, code) {
if (mark === '=') return '"+(' + code + ')+"';
var exec = require('child_process').exec,
path = require('path');
var TianmaCmd = function(tianma, cwd) {
this.tianma = tianma || path.join(__dirname, '../node_modules/tianma/bin/tianma');
this.cwd = cwd || path.join(__dirname, '../node_modules/tianma/deploy');
};
TianmaCmd.prototype = {
_exec: function(cmd, callback) {
<html>
<head>
<title>tianmaGUI</title>
</head>
<body>
<script type="text/javascript">
document.write('node version:' + process.version);
</script>
</body>
</html>
@wiky
wiky / app.js
Last active August 29, 2015 13:57
var fs = require('fs'),
path = require('path'),
TianmaCmd = require('./tianma-cmd'),
doc = window.document,
workdir = doc.getElementById('workdir'),
tianma = TianmaCmd();
workdir.addEventListener('change', function(evt) {
var dir = this.value,
configArr = [];
@wiky
wiky / md5.js
Created October 28, 2014 11:23
md5
var crypto = require('crypto');
function md5 (text) {
return crypto.createHash('md5').update(text).digest('hex');
};