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
console.time('p1'); | |
var data, n = 1000000; | |
for(var i = 0 ; i < n; i ++) data = { foo: 123, bar: i }; | |
console.timeEnd('p1'); | |
console.time('p2'); | |
for(var i = 0 ; i < n; i ++) data = JSON.parse("{\"foo\":123,\"bar\":"+i+"}"); | |
console.timeEnd('p2'); | |
//p1: 872ms - 計時器停止 | |
//p2: 1900ms - 計時器停止 |
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 valid_list = []; | |
var diffCount = function(a, b) { | |
var result = 0; | |
if(parseInt(a/100000)%10 != parseInt(b/100000)%10) result++; | |
if(parseInt(a/10000)%10 != parseInt(b/10000)%10) result++; | |
if(parseInt(a/1000)%10 != parseInt(b/1000)%10) result++; | |
if(parseInt(a/100)%10 != parseInt(b/100)%10) result++; | |
if(parseInt(a/10)%10 != parseInt(b/10)%10) result++; | |
if(parseInt(a/1)%10 != parseInt(b/1)%10) result++; | |
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
var jsdom = require('jsdom'); | |
var $ = require('jquery')(jsdom.jsdom('<html></html>').defaultView); | |
var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; | |
parseHTML = function(html){ | |
//this extract body function may have a bug | |
var html = '<body'+html.split('<body')[1].split('</body>')[0]+'</body>' | |
return $(html); | |
}; |
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
//{{ PromisePool | |
/* Usage: | |
var promise_pool = new PromisePool([concurrency_limit]); | |
* concurrency_limit: n of concurrency promices executions | |
generate a PromisePool | |
promise_pool.push(fn); | |
* function: the function to generate promise object | |
push a function into PromisePool, this functipn will generate promise object | |
but the real Promise object has *NOT* been generated yet |
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
//{{ PromisePool | |
/* Usage: | |
var promise_pool = new PromisePool([concurrency_limit]); | |
* concurrency_limit: n of concurrency promices executions | |
generate a PromisePool | |
promise_pool.push(function, args); | |
* function: the function to generate promise object | |
* args: the arguments array of function | |
push a promise object into PromisePool, but the real Promise object has *NOT* been generated yet |
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
//取得自己牆上按讚數排行 | |
/* | |
使用方式, | |
0. 安裝 gClipboard: https://addons.mozilla.org/zh-TW/firefox/addon/grassboy-clipboard/ | |
1. 到 https://www.facebook.com/[你的臉書id]/photos_all 進入你的相片頁,並捲開所有相片 | |
2. Firefox 下按 Shift+F4 | |
3. 貼入這整段文字 | |
4. 頁面會將結果複製到剪貼簿裡 | |
5. 貼到記事本,就是你所有相片的按讚數排名了~ | |
*/ |
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
//Get the dataURL of Endomondo's Map Path | |
//requirement: jQuery | |
javascript: (function() { | |
var input = $('#wokoutMapContainer .gm-style div:first div:first')[0]; | |
var final = { | |
x1: Number.MAX_VALUE, | |
y1: Number.MAX_VALUE, | |
x2: Number.MIN_VALUE, | |
y2: Number.MIN_VALUE | |
}; |
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 gDataURL = function(opts){ | |
opts = opts || {}; | |
opts.onload = opts.onload || function(r){ | |
console.log(r); | |
}; | |
opts.url = opts.url || location.href; | |
var oReq = new XMLHttpRequest(); | |
oReq.open("GET", opts.url, true); | |
oReq.responseType = "blob"; |
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
Handler function threw an exception: [Exception... "Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsIWebProgress.DOMWindow]" nsresult: "0x80004002 (NS_NOINTERFACE)" location: "JS frame :: resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webbrowser.js :: TabActor.prototype._docShellsToWindows/< :: line 1132" data: no] | |
Stack: TabActor.prototype._docShellsToWindows/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webbrowser.js:1132:11 | |
TabActor.prototype._docShellsToWindows@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webbrowser.js:1129:1 | |
TabActor.prototype._notifyDocShellsUpdate@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webbrowser.js:1155:19 | |
TabActor.prototype._onDocShellCreated/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webbro |
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 div = $('<div class="item" data-foo="bar">'); | |
alert(div.data('foo')); | |
div.attr('data-foo', 'barbarbar'); | |
alert(div.data('foo')); |
NewerOlder