Skip to content

Instantly share code, notes, and snippets.

@wiky
wiky / uuid.js
Last active December 22, 2015 10:58
uuid
function uuid() {
return (Math.random()).toString(36).slice(2, 7);
}
@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 / 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 / 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 / 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 / event.js
Last active December 17, 2015 12:29
(function(exports) {
var idCounter = 0,
PREFIX = '_',
PREFIX_REG_EXP = new RegExp('^' + PREFIX + '+');
var uniqueId = function(prefix) {
var id = ++idCounter + '';
return prefix ? prefix + id : id;
};
@wiky
wiky / tmpl.js
Last active December 17, 2015 04:28
a simple javascript templating
(function (exports) {
var settings = {
open: '<%',
close: '%>',
evaluate: '',
interpolate: '='
};
var matcher = new RegExp([
settings.open,
@wiky
wiky / list.md
Last active December 15, 2015 12:39
My Favorite st2 plugins

Package Control

Sublime Package Control

import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')

Sublime Text 3

import urllib.request,os; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), 'wb').write(urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ','%20')).read())
@wiky
wiky / substitute.js
Created March 25, 2013 02:29
simple template, data substitute
function substitute(str, obj) {
if (typeof str === 'string' && typeof obj === 'object') {
str = str.replace(/\{(\w+)\}/gi, function(s, k) {
return (typeof obj[k] === 'undefined') ? s : obj[k];
}).replace(/(\\\{)|\\\}/g, function(s, k) {
return k ? '{' : '}';
});
}
return str;
}
@wiky
wiky / event.js
Created August 29, 2012 04:37
Serial Event Listener
function addEvent(el, type, handler) {
if (el.attachEvent) { // IE
// 为元素的事件类型创建一个哈希表
el._events = el._events || {};
if (!handler) {
return;
}
// 取得事件处理函数的数组的引用
var handlers = el._events[type];
if (handlers) {