Skip to content

Instantly share code, notes, and snippets.

@chenwery
chenwery / encodedecode.js
Created October 23, 2015 06:50
HTML Encode & Decode
var js = {}
js.lang = {}
js.lang.String = function () {
this.REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
this.REGX_HTML_DECODE = /&\w+;|&#(\d+);/g;
this.REGX_TRIM = /(^\s*)|(\s*$)/g;
一个同样的url返回不同内容的时候,服务器根据它来判断返回不同的内容。
例如
Vary: Accept-Encoding
Accept-Encoding: gzip;
对应====>
Content-Encoding: gzip;
的内容
也就是说 Vary 字段用于列出一个响应字段列表,告诉缓存服务器遇到同一个 URL 对应着不同版本文档的情况时,如何缓存和筛选合适的版本。
@chenwery
chenwery / throttle-AND-debounce.js
Last active August 29, 2015 14:09
throttle AND debounce
var throttle = function (fn,delay, immediate, debounce) {
var curr = +new Date(),//当前事件
last_call = 0,
last_exec = 0,
timer = null,
diff, //时间差
context,//上下文
args,
exec = function () {
last_exec = curr;
@chenwery
chenwery / callback.js
Last active August 29, 2015 14:01
跨域解决方法
//parse and organize all QS parameters in a more comfortable way
var params = {};
if (location.search.length > 1) {
var i, arr = location.search.substr(1).split("&");
for (i = 0; i < arr.length; i++) {
arr[i] = arr[i].split("=");
params[arr[i][0]] = unescape(arr[i][1]);
}
}
@chenwery
chenwery / mysql-simple-config.sh
Last active August 29, 2015 14:01
mysql-simple-config
#install
yum install mysql-server
#auto start on rebooting
chkconfig mysqld on
#start
service mysqld start
(service mysqld stop)
(service mysqld restart)
@chenwery
chenwery / browser.js
Created April 22, 2014 06:53
JS判断移动端访问设备并解析对应CSS
// 判断是否为移动端运行环境
// wukong.name 20130716
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?mobile")&lt;0){
try{
@chenwery
chenwery / syntaxhighlighter-usage.html
Last active August 29, 2015 13:57
syntaxhighlighter
<link rel="stylesheet" type="text/css" href="./syntaxhighlighter/styles/shCoreDefault.css">
<script src="./syntaxhighlighter/scripts/shCore.js"></script>
<script src="./syntaxhighlighter/scripts/shBrushJScript.js"></script>
<script src="./syntaxhighlighter/scripts/shBrushXml.js"></script>
<script src="./syntaxhighlighter/scripts/shBrushCss.js"></script>
<script>SyntaxHighlighter.all();</script>
@chenwery
chenwery / query-url.js
Created March 4, 2014 12:53
query-url.js
var qUrl = (function() {
var q = window.location.search;
q = q ? q.split('?')[1].split('&') : [];
var query = {};
jQuery(q).each(function(i) {
var t = q[i].split('=');
query[t[0]] = t[1]
});
return query;
})();
@chenwery
chenwery / ajaxfileupload.js
Created February 28, 2014 13:43
ajax file upload
jQuery.extend({
createUploadIframe: function(id, uri)
{
//create frame
var frameId = 'jUploadFrame' + id;
var iframeHtml = '<iframe id="' + frameId + '" name="' + frameId + '" style="position:absolute; top:-9999px; left:-9999px"';
if(window.ActiveXObject)