Skip to content

Instantly share code, notes, and snippets.

View cognitom's full-sized avatar

Tsutomu Kawamura cognitom

View GitHub Profile
@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 / 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]"
SELECT
creator,
description,
eid,
end_time,
event_subtype,
event_type,
hide_guest_list,
host,
location,
@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] || ''
@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 / 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: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 / gist:1625389
Created January 17, 2012 07:12
Create archive without .DS_Srore files
zip -r Archive.zip TargetDirectory -x "*.DS_Store"
@cognitom
cognitom / add_file_size_to_link.php
Created January 4, 2012 15:53
PDFファイルのリンクに容量を記載する
@cognitom
cognitom / function.byte2str.php
Created January 4, 2012 10:33
バイト数を分かり易い表記に
function byte2str($size){
$kb=1024;
$mb=1048576;
$gb=1073741824;
$tb=1099511627776;
if(!$size) return '0 B';
elseif($size<$kb) return $size.' B';
elseif($size<$mb) return round($size/$kb, 0).' KB';
elseif($size<$gb) return round($size/$mb, 2).' MB';
elseif($size<$tb) return round($size/$gb, 2).' GB';