Skip to content

Instantly share code, notes, and snippets.

View island205's full-sized avatar
🎯
Focusing

Zhi Cun island205

🎯
Focusing
View GitHub Profile
@island205
island205 / animate.coffee
Created July 9, 2012 05:04
time animate function
animate=do ->
requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame ||
(callback)->
setTimeout(->
callback(new Date())
return
@island205
island205 / h5g
Created July 18, 2012 22:40 — forked from wintercn/h5g
HTML5 Canvas Game Template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<!--允许全屏-->
<meta content="yes" name="apple-mobile-web-app-capable"/>
<meta content="yes" name="apple-touch-fullscreen"/>
<!--禁止电话号码和邮箱识别-->
@island205
island205 / gist:3347070
Created August 14, 2012 06:55
数据处理
isInteger=(n)->
n%1 == 0
foo=(num)->
num=parseInt num, 10
re=[]
if num == 0
return num
while num > 0
@island205
island205 / gist:3607097
Created September 3, 2012 06:00
兼容AMD,nodejs/commonjs规范的模块定义-读knockoutjs源码
//闭包执行一个立即定义的匿名函数
! function (factory) {
//factory是一个函数,下面的koExports就是他的参数
// Support three module loading scenarios
if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {
// [1] CommonJS/Node.js
// [1] 支持在module.exports.abc,或者直接exports.abc
var target = module['exports'] || exports; // module.exports is for Node.js
factory(target);
@island205
island205 / Lexer.coffee
Created September 19, 2012 01:49
lexer
class Lexer
@EOF:-1
@EOF_TYPE:1
p:0
c:""
constructor:(@input)->
@c = @input[@p]
###
get next char
###
#https://developer.mozilla.org/en-US/docs/JavaScript/ECMAScript_6_support_in_Mozilla
Map = Map || do ->
id = 0
keyToObj = {}
keyToValue = {}
unique = ->
"Map_#{id++}"
getKeyByObj = (obj)->
for own key, value of keyToObj
if obj is value
@island205
island205 / merge_sort.coffee
Created October 24, 2012 14:18
合并排序
merge = (left, right)->
i = j = 0
arr =[]
while i < left.length || j < right.length
if i is left.length
arr = arr.concat right.slice j, right.length
break
if j is right.length
arr = arr.concat left.slice i, right.length
break
bubbleSort = (arr)->
return arr if arr.length <= 1
for i in [arr.length...1]
for j in [0...i-1]
if arr[j] > arr[j+1]
temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
arr
#test
insertSort = (arr)->
for i in [1...arr.length]
for j in [i-1..0]
if arr[j] > arr[j+1]
temp = arr[j]
arr[j] = arr[j+1]
arr[j+1] = temp
arr
#test
selectionSort = (arr)->
for i in [0...arr.length - 1]
min = arr[i]
minI = i
for j in [i+1...arr.length]
if min > arr[j]
minI = j
if i isnt minI
temp = arr[i]
arr[i] = arr[minI]