This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// version 1 | |
function search(name) { | |
name = name.replace(/[\[]/g, '\\\[').replace(/[\]]/g, '\\\]'); | |
name = encodeURIComponent(name); | |
var regex = new Regex('[/?&]' + name + '=([^&#]*)'); | |
var results = regex.exec(window.location.search); | |
return results === null ? '' : decodeURIComponent(results[1]); | |
} | |
// version 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct str | |
{ | |
int len; | |
char s[0]; | |
}; | |
struct foo | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 简易ajax | |
function ajax(options) { | |
var xhr = new XMLHttpRequest(); | |
xhr.open(options.type, options.url, true); | |
xhr.send(options.data || ''); | |
xhr.onreadystatechange = function() { | |
if(xhr.readyState === 4 && xhr.status === 200) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mix(arrays) { | |
if (arguments.length < 1) return []; | |
var allElems = []; | |
var repeatRegStr = []; | |
for (var i = 0, len = arguments.length; i < len; ++i) { | |
if (i === 0) { | |
repeatRegStr.push('(-?(?!0\\d)\\d+(?:\\.\\d+|)(?:[eE][+-]?\\d+|))'); | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 模拟费时的异步操作 | |
function asyncCall(fn) { | |
var t = (Math.random()*3 + 2) * 1000; | |
setTimeout(function() { | |
fn(t); | |
}, t); | |
} | |
// 写日志 | |
function trace(info) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mulMatrix(a, b) { | |
return [ | |
a[0]*b[0] + a[1]*b[2], | |
a[0]*b[1] + a[1]*b[3], | |
a[1]*b[0] + a[3]*b[2], | |
a[1]*b[1] + a[3]*b[3] | |
]; | |
} | |
function powMatrix(a, n) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. 打开 http://w.qq.com | |
// 2. 登录 | |
// 3. 选择交谈对象 | |
// 4. 进入控制台 | |
// 5. 粘贴运行 | |
// 6. Chrome | |
(function () { | |
var textNode = $('#chat_textarea'); | |
var sendBtn = $('#send_chat_btn'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
U2FsdGVkX1+LjAu66wH3YKi/0y+/9zwmRH/m51CbZ6Xugm1vIskAIAuefSPRJbwI | |
BYevFe0yFe0Jc5kKICRgEj/gQ2tL8ypcsjJbiNll8KkQO+hZAaPrkBSTHTgDrrC9 | |
qCsNgytGl6o6XiP2cs7kVinRMdyec9pwqKFRzrSlO8fFaWvIH2eUiavsnOoWeQUB | |
APSKI17IjcqKAeFDzTwTiJ5HzB4VvIVZmyU2bTLtH9YuSaVSSH+87OCDEakHG6jE | |
uENsvY4odmQKzJjcZlaiFQZsS56r5/bu597z3o21ikFIlKsLpFwDPlkpvrDtduk+ | |
TDAiAk7zSuf63HFcd76MCUck9ZkZKSG+Ic21ORpwJQUIDPTm/L0EG70NBz6NTy1f | |
0aNZ6e/Z7mXeSDJlqDX+cByQSWdSoSkW1cKzpNbc39L/TYj+KhFhQERUGmr/k2oF | |
A06EkusW5+ddO3kglvWWzJJFm0uKe6HJhL5QIIIn1dK4nwKujHhL/jeCasozF8d6 | |
AB4+FojORr/zWzmOiHSdq1zV82f9sqRGBXoBPIX8SojGtgHqjR2JNEDqCU0XxZSY | |
mMsq5/ENc/1mGYn1Am61ii0T6WPCnPxztw2/Ubsgw6Amt3YE1OZitocunFoOfLL7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var flattenWithReduce = (function () { | |
function flatten(prev, curr, i, a) { | |
var result; | |
if(Array.isArray(curr)) { | |
result = prev.concat(curr.reduce(flatten, [])); | |
} else { | |
result = prev.concat(curr); | |
} | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// [" 1 ", "2", "", " ", "3", "4 ", "5 "] => ["1", "2", "3", "4", "5"] | |
function foo(arr) { | |
return arr.map(function (e) { | |
return e.trim(); | |
}).filter(function (e) { | |
return e.length > 0; | |
}); | |
} |