Skip to content

Instantly share code, notes, and snippets.

@mindon
mindon / link-tags.js
Created March 3, 2014 01:27
Link keywords in your blog powered by Octopress
@mindon
mindon / activate-links.js
Created March 3, 2014 02:18
Detect URLs in plain text and active them as HTML links
@mindon
mindon / keep-white-spaces.js
Last active August 29, 2015 13:57
Replace white space safely with  
var s = "a b c";
s = s.replace(/ /g, '  '); // keep the text wrappable
// s = s.replace(/ /g, ' '); // failed to wrap
@mindon
mindon / replace-all.js
Last active August 29, 2015 13:57
String replaceAll in JavaScript
String.prototype.replaceAll = function(s, t) {return this.split(s).join(t)};
@mindon
mindon / string-limit.js
Last active August 29, 2015 13:57
String simple size / limit / html / text
// usage
// var s = "This is a 非常长的字符串This is a 非常长的字符串This is a 非常长的字符串This is a 非常长的字符串";
// document.write(s.limit(20));
// character length
String.prototype.size = function() {
var s = this, n = 0; // [u4e00-u9fa5] chinese
if(s) n = s.replace(/[^\x00-\xff]/g, "**").length;
return n;
};
@mindon
mindon / chrome-network
Created March 13, 2014 05:50
Chrome: Deep in the guts of the network stack
chrome://predictors - omnibox predictor stats (check 'Filter zero confidences')
chrome://net-internals#sockets - current socket pool status
chrome://net-internals#dns - Chrome's in-memory DNS cache
chrome://histograms/DNS - histograms of your DNS performance
chrome://dns - startup prefetch list and subresource host cache
http://www.igvita.com/2012/06/04/chrome-networking-dns-prefetch-and-tcp-preconnect/
@mindon
mindon / bups.js
Last active August 29, 2015 14:07
A simple JavaScript Sub/Pub
/* ----------- simple sub/pub --------------
* -- Author: Mindon Feng http://mindon.github.com
* -- Usage:
* BuPS.subscribe("event-string", function(data, cmd){});
* BuPS.publish("event-string", data);
*/
var BuPS={}, _DEBUG=false;
;(function(){
var cmds = {};
@mindon
mindon / jsinit
Last active August 29, 2015 14:08
load no-critical js
!function(e,t,r,b){function n(){for(;d[0]&&"loaded"==d[0][f];)b&&b(d[0].src),c=d.shift(),c[o]=!i.parentNode.insertBefore(c,i)}for(var s,a,c,d=[],i=e.scripts[0],o="onreadystatechange",f="readyState";s=r.shift();)a=e.createElement(t),'async'in i?(a.async=!1,(b?a.onload=b:!0),e.head.appendChild(a)):i[f]?(d.push(a),a[o]=n):(window._j$c=b,e.write("<"+t+' src="'+s+'" defer'+(b?' onload="_j$c(this.src)"':'')+'></'+t+">")),a.src=s}(document,"script",[
"http://code.jquery.com/jquery-1.9.1.min.js",
"http://www.slidesjs.com/js/jquery.slides.min.js"
], function(e){
var src = typeof e=='string'? e: this.src;
console.log(src);
});
@mindon
mindon / fit.html
Last active August 29, 2015 14:23
Responsive Mobile Web in Single Page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="Author" content="mindon@gmail.com">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="format-detection" content="telphone=no, email=no" />
<meta name="HandheldFriendly" content="true">
@mindon
mindon / appup.js
Created July 29, 2015 07:02
launch a mobile app from mobile web or inside wechat, or goes to app website to download
;// to launch mobile app
var insideWeChat = typeof window.WeixinJSBridge == "object";
var isMobileDevice = 'ontouchstart' in window || /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB10|IEMobile|Opera Mini/i.test(navigator.userAgent);
;(function(document, window){ //
var ua = navigator.userAgent;
var tid, callfn, duration = 1300;
function bind(el, en, fn, useCapture){
el.addEventListener ? el.addEventListener(en, fn, useCapture||false): (el.attachEvent ? el.attachEvent('on'+en, fn) : el['on'+en]=fn);
}
function unbind(el, en, fn, useCapture){