Skip to content

Instantly share code, notes, and snippets.

View yyx990803's full-sized avatar

Evan You yyx990803

View GitHub Profile
@yyx990803
yyx990803 / task.js
Created July 3, 2013 15:07
a grunt task for working with an appengine app
grunt.registerTask( 'dev', 'start deving y\'all', function () {
grunt.task.run('watch')
grunt.util.spawn({
cmd: 'dev_appserver.py',
args: ['./app.yaml'],
opts: {
stdio: 'inherit'
}
var now = new Date(),
year = now.getYear() + 1900,
first = new Date(year, 0, 0),
elapsedMs = now.getTime() - first.getTime(),
elapsedDays = ~~(elapsedMs / (1000 * 60 * 60 * 24))
if (elapsedDays === Math.pow(2, 8)) {
console.log("Yes. Happy Programmers' Day!")
} else {
console.log("No. Get back to work.")

Origin

Seed started out as a practice to create a data binding library that mimics Angular. While implementing it I also shaped the API to get rid of several things I don't like about Angular:

  • auto magic compile and no familar instantiating objects
  • have to be aware of how $digest loop works
  • doesn't play well with module build tools, e.g. component & browserify
  • bundles too much stuff (I just want data binding, something lightweight)

Personal preferences

// npm install gruntfile-yaml
// short version:
module.exports = require('gruntfile-yaml')
// or if you still need custom js:
module.exports = function (grunt) {
require('gruntfile-yaml')(grunt)
// do your own stuff...
}
@yyx990803
yyx990803 / umd.js
Created January 27, 2014 16:40
umd
;(function(){
// module content
if (typeof exports == "object") {
module.exports = require("{{configName}}");
} else if (typeof define == "function" && define.amd) {
define(function(){ return require("{{configName}}"); });
} else {
this["{{standaloneName}}"] = require("{{configName}}");
<script src="https://npmcdn.com/vue@next/dist/vue.js"></script>
<script src="https://npmcdn.com/vue-router@next"></script>
<style>
.router-link-active {
color: red;
}
</style>
<div id="app">
<side-bar></side-bar>
<script src="https://npmcdn.com/vue@next/dist/vue.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/animatecss/3.5.2/animate.min.css">
<style>
.done {
text-decoration: line-through;
}
.todo {
transition: all 0.5s ease;
height: 30px;
const marky = require('marky')
const render = Vue.prototype._render
const update = Vue.prototype._update
const camelize = str => str && Vue.util.camelize(str)
function getName (vm) {
if (!vm.$parent) return 'root'
return (
camelize(vm.$options.name) ||
camelize(vm.$options._componentTag) ||
@yyx990803
yyx990803 / props.md
Last active March 28, 2017 11:39
关于应不应该把属性的默认值放在prototype里

TL,DR: 务必总是在构建函数里定义实例属性。

在小胖的PoorPhy物理库里,有很多类似这样的代码:

function WorldA () {
  // ...
}

WorldA.prototype = {