Skip to content

Instantly share code, notes, and snippets.

View cognitom's full-sized avatar

Tsutomu Kawamura cognitom

View GitHub Profile
@cognitom
cognitom / part-of-yinyang.coffee
Created March 6, 2012 04:48
YinYangのテンプレートタグ用正規表現 for codeReview.cafe
re =
pend: /<!--\{end\}-->/
more: /<!--\{more\}-->/
pvar: /<!--\{(@[a-zA-Z0-9_\.\#>=\[\]]+|[a-zA-Z][a-zA-Z0-9_\.]*)(\|.*?)*\}-->/
ivar: /\#\{(@[a-zA-Z0-9_\.\#>=\[\]]+|[a-zA-Z][a-zA-Z0-9_\.]*)(\|.*?)*\}/
loop: /<!--\{[a-zA-Z][a-zA-Z0-9_\.]* in (@[a-zA-Z0-9_\.\#>=\[\]]+|[a-zA-Z][a-zA-Z0-9_\.]*)\}-->/
if value.match re.pend then @ignore = false; @parent
else if value.match re.more then @ignore = true; @
else unless @ignore
if value.match re.pvar then @_add 'child', new TemplateVar @, value.replace(/<!--{|}-->/g, ''), true
@cognitom
cognitom / part-of-yinyang.coffee
Created March 6, 2012 04:49
YinYangのTemplateVarクラス for codeReview.cafe
class TemplateVar extends Template
constructor: (@parent = null, @value = '', @ignore = false) ->
fs = @value.split '|'
@value = fs.shift()
@filters = (YinYang.createFilter f for f in fs)
@children = []
display: (localValues) ->
@localValues = localValues
v = if @value[0] == '@' then @displayDom() else @displayVar()
v = filter.process v for filter in @filters
@cognitom
cognitom / part-of-yinyang.coffee
Created March 6, 2012 04:51
YinYangのFilterクラス for codeReview.cafe
# [Filters]
# thru filter
class YinYang.filter
constructor: (@args) ->
process: (val) -> val
# default filter
# http://osscafe.github.com/yinyang/english/api.html#filter|default
class YinYang.filters.default extends YinYang.filter
process: (val) -> val || @args[0] || ''
@cognitom
cognitom / Filterクラス.coffee
Created March 6, 2012 04:52
YinYangの変更箇所 for codeReview.cafe
# [Filters]
# thru filter
class YinYang.filter
constructor: (@args) ->
process: (val) -> val
# default filter
# http://osscafe.github.com/yinyang/english/api.html#filter|default
class YinYang.filters.default extends YinYang.filter
process: (val) -> val || @args[0] || ''
SELECT
creator,
description,
eid,
end_time,
event_subtype,
event_type,
hide_guest_list,
host,
location,
@cognitom
cognitom / split.coffee
Created March 11, 2012 07:37
Cross-browser split function for CoffeeScript
# Cross-Browser Split 1.0.1 for CoffeeScript
# (c) Tsutomu Kawamura @OSSCafe; just converting to CoffeeScript
# (c) Steven Levithan <stevenlevithan.com>; MIT License
# An ECMA-compliant, uniform cross-browser split method */
if !cbSplit
cbSplit = (str, separator, limit) ->
# if `separator` is not a regex, use the native `split`
return cbSplit._nativeSplit.call str, separator, limit if Object::toString.call(separator) isnt "[object RegExp]"
@cognitom
cognitom / array_reduce.php
Created March 23, 2012 11:12
多元配列の一部を合計する
$sum = array_reduce($vals, create_function('$ret,$val','return $ret + $val[0];'), 0);
@cognitom
cognitom / gist:2192416
Created March 25, 2012 08:41
Syntax check multiple PHP files in the current directory
find . -name \*.php -exec php -l "{}" \;
@cognitom
cognitom / level1-challenge5.lolcode
Created April 1, 2012 05:06
LEVEL 1 CHALLENGE 5
HAI
I HAS A ANIMAL
GIMMEH ANIMAL
BOTH SAEM ANIMAL AN "CAT", O RLY?
YA RLY
VISIBLE "U HAS KITTEH"
NO WAI
VISIBLE "KITTEH R 2 GUD 4 U"
OIC
@cognitom
cognitom / not-pass.html
Created April 25, 2012 18:42
Safari doesn't say "PASS"
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.js"></script>
</head>
<body>
<script>
url = 'https://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://www.engadget.com/rss.xml&callback=?';
$.getJSON(url, function(){
alert('PASS');