Skip to content

Instantly share code, notes, and snippets.

View fillano's full-sized avatar

Hsu Ping Feng fillano

View GitHub Profile
function * gen(){}
var g = gen();
g.throw('got an error.');
//拋出一個例外,錯誤訊息是 'got an error.'
function * gen() {
console.log('start');
var got = yield 'called';
console.log(got);
}
var g = gen();
var a = g.next();
//顯示start
var b = g.next('hello generator');
//顯示hello generator
function * gen() {
console.log('start');
yield "called";
}
var g = gen();
//nothing happened
var a = g.next();
//顯示start
console.log(a.value);
//顯示called
@fillano
fillano / test920.html
Created March 5, 2014 17:45
getting started example from traceur-compiler
<!DOCTYPE html>
<html>
<body>
<script src="https://traceur-compiler.googlecode.com/git/bin/traceur.js"
type="text/javascript"></script>
<script src="https://traceur-compiler.googlecode.com/git/src/bootstrap.js"
type="text/javascript"></script>
<script>
traceur.options.experimental = true;
</script>
@fillano
fillano / async_recurser.js
Last active December 24, 2015 06:58
list files in specified directory
module.exports = function(le, cb, payload) {
var count = 0;
this.getRecurser = function() {
return (function(f) {
return f(f);
})(function(f) {
count++;
return le(function() {
var args = Array.prototype.slice.call(arguments, 0);
return f(f).apply(f, args);
<?php
$units = array(3, 8, 4, 5);
$cn = 0;
$units = array_map(function($a) use(&$cn) {
$cn++;
return array($a, $cn);
}, $units);
$first = array_shift($units);
$s = array_reduce($units, function($res, $item) {
return $res." UNION SELECT ".$item[0].", ".$item[1]." ";
@fillano
fillano / test786.html
Created August 21, 2012 02:55
simple shared whiteboard with canvas and websocket
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<style>
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
@fillano
fillano / app.js
Created August 13, 2012 12:02
test cookie and res.redirect()
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.cookie('test', '123456');
res.cookie('test', '0');
res.redirect('/a');
});
app.get('/a', function(req, res) {
res.send('hello cookie test');
@fillano
fillano / test798.js
Created June 26, 2012 02:58
trampoline sample
function factorial(n, a) {
a = a||1;
if(n===0) {
return a;
}
return function() {
return factorial(n-1, a*n);
}
}
@fillano
fillano / test793.html
Created May 14, 2012 10:47
demo for Javascript object clone and traits
<html>
<body>
<body>
</html>
<script>
function trait(spec) {
this.traits = {};
for(var i in spec) {
if(spec.hasOwnProperty(i)) {
if(spec[i]['deps']&&spec[i]['func']&&typeof spec[i]['func']==='function') {