Skip to content

Instantly share code, notes, and snippets.

View Gerhut's full-sized avatar
🫥
Can't see me can't see me

George Cheng Gerhut

🫥
Can't see me can't see me
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
funcProto = Function.prototype
@Gerhut
Gerhut / values.styl
Created December 29, 2014 06:56
给属性附加循环列表值
values(property, values)
length = length(values)
for value, index in values
&:nth-child({length}n + {index})
{unquote(property)} value
/* li
* values(background-color, #8185cd #7cd7c5 #65adeb #ee8e69)
*
* yields
flatten = (list, result = []) ->
for value in list
if Array.isArray value
flatten value, result
else
result.push value
return result
console.log flatten [(->), [[new Date], /foo/g]]
flatten = (list, result = []) ->
for value in list
if Array.isArray value
flatten value, result
else
result.push value
return result
console.log flatten [(->), [[new Date], /foo/g]]
flatten = (list) ->
result = []
lists = []
while list? and not list in lists
lists.push list
result.push list[0]
list = list[1]
return result
console.log flatten [1, ['foo', [(->), [a: no, [new Date, [/bar/g]]]]]]
@Gerhut
Gerhut / watcher.sh
Last active August 29, 2015 14:03
simple-f2e-watcher
#!/bin/sh
jade -P -w *.jade &
stylus -u nib -w style.styl &
coffee -c -w *.coffee
@Gerhut
Gerhut / curly.js
Created June 19, 2014 03:56
{}的二义性
{} + [] // => {}; +[] => 0
[] + {} // => '' + '[object Object]' => '[object Object]'
{} + [] == [] + {} // => {}; 0 == '[object Object]' => false
({} + [] == [] + {}) // => '[object Object]' + '' == '' + '[Object Object]' => true
/*
知识点:
@Gerhut
Gerhut / simple-async.coffee
Last active August 29, 2015 14:02
简单的函数式回调链构造器
#!/usr/bin/env coffee
module.exports = SimpleAsync = (funcs...) ->
callback = (args...) ->
funcs.shift()? args..., callback
return
inner = (argsOrFuncs...) ->
if typeof argsOrFuncs[0] is 'function'
funcs.push argsOrFuncs...
inner
var x = 10;
foo = {
x: 20,
bar: function () {
var x = 30;
return this.x;
}
}
/*