OzJS is a CommonJS Asynchronous Modules compatible implementation
blog post: http://www.limboy.com/2010/12/19/module-and-compiler-for-common-js/
slide in D2forum:
$(new Image()).load(function(){ | |
console.timeEnd("1"); | |
$(new Image()).load(function(){ | |
console.timeEnd("2"); | |
}).attr('src', "http://shop.10010.com/images/iphone/iphone_3GS.jpg"); | |
console.time("2"); | |
10/24/09 6:08:17 PM MacVim[391] -[MMVimController sendMessage:data:]@352: processInput:data: failed: pid=396 id=1 msg=SetMouseShapeMsgID reason=[NSPortCoder sendBeforeTime:sendReplyPort:] timed out (278071697.436471 278071697.438507) 1 |
// javascript版二分法: | |
function bsearch(v, data, pre){ | |
pre = pre || 0; | |
var l = data.length, | |
half = Math.floor(l/2), | |
c = v - data[half]; | |
if (c > 0) | |
return bsearch(v, data.slice(half + 1), pre + half + 1); | |
else if (c < 0) |
# python版二分法: | |
import random, math | |
def bsearch(v, data, pre=0): | |
l = len(data) | |
if l <= 0: | |
return -1; | |
half = int(math.floor(l/2)) | |
c = v - data[half] |
(defun factorial (x) | |
(flet ((fact (x &optional (res 1)))) | |
(if (= 1 x) | |
res | |
(factorial (1- x) (* res x))) |
OzJS is a CommonJS Asynchronous Modules compatible implementation
blog post: http://www.limboy.com/2010/12/19/module-and-compiler-for-common-js/
slide in D2forum:
var tmp = document.createElement('DIV'); | |
tmp.innerHTML = '<canvas width="512" height="512" style="position:fixed;top:10px;right:10px;z-index:99999;"></canvas>'; | |
var e = tmp.firstChild; | |
document.body.appendChild(e); | |
var ctx = e.getContext('2d'); | |
ctx.fillStyle = "#000"; | |
ctx.fillRect(0, 0, 512, 512); | |
ctx.fillStyle = "#fff"; | |
for (var y = 0, x; y < 512; y++) { | |
for (x = 0; x < 512; x++) { |
TUI.swfobject = (function(TUI){ | |
var uuid = 0; | |
var isie = !(navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length); | |
var webkit = TUI.browser.webkit; | |
var flashMC = TUI.getFlashMC; | |
var template = { | |
'object': '<object id="<%=id%>" <%=classid%> width="<%=width%>" height="<%=height%>" name="<%=name%>" <%=data%> style="<%=style%>" <%=mimetype%> >', | |
'embed': '<embed id="<%=id%>" width="<%=width%>" height="<%=height%>" flashvars="<%=flashvars%>" quality="high" name="<%=name%>" src="<%=src%>" style="<%=style%>" <%=mimetype%> ', | |
'pluginspage': '<a id=<%=id%> class="tui_noflash" href="#" style="width:<%=width%>;height:<%=height%>;display:block;overflow:hidden;cursor:pointer;<%=style%>" onclick="<%=fn%>()">需要flashplayer插件,点击安装</a>' | |
}; |
/** | |
* TUI::utilities::flash | |
* @created: Dexter.Yy | |
* @modified: $Author$ | |
* @version: $Rev$ | |
*/ | |
/** | |
* @public 获取指定的flash对象 | |
* @note 用于调用flash里提供的方法 |