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 / 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
###
@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 / 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 / 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 / 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 / gist:2835281
Created May 30, 2012 09:59
模板语言语法分析
{{Variable}}
{{#if conditions}}
BLOCK
{{/if}}
{{#if conditions}}
BLOCK
{{#elseif conditions}}
ELSEIF BLOCK
###
AOP开始
###
DO =
objs: {}
before: (fn, obj, sFn, c) ->
after: (fn, obj, sFn, c) ->
_inject: (when_, fn, obj, sFn) ->
var Vector;
Vector = (function() {
/*
构造函数这里使用了默认参数和属性参数
*/ function Vector(x, y) {
var vector;
this.x = x != null ? x : 0;
this.y = y != null ? y : 0;
if (typeof this.x === "object") {
/*
class Vector
###
构造函数这里使用了默认参数和属性参数
###
constructor:(@x=0,@y=0) ->
if typeof @x is "object"
###
这里的vector为了解决给@x赋值的问题,当然使用
@[email protected]
@[email protected]
new Vector
new Vector 1,1
new Vector {x:1,y:1}